How do I make THIS work

Get help using Construct 2

Post » Thu Jul 31, 2014 12:01 pm

For my Situation...
Im working with the Free Edition.
I have some Gun Objects. One of them is named "Pistol" it has instance variables in it so i can access my Array with them.
Pistol.WeaponID = 0
Pistol.ClipSize = 1
Pistol.currentAmmo = 11

i have an Array with weaponstats in it.
Array.Width = 12
Array[0,1] = 6 ==> Size of the Clip of that weapon
Array[0,11] = 6 ==> Ammount of Ammo inside that Clip/Weapon

When i start my game the array is getting intialized with values like i want.
When i shoot my weapon (the first time) it substracts 1 from Array[11] until empty or getting reloaded.
But when i reload im doing:

Array --> Set value at(Pistol.WeaponID, Pistol.currentAmmo) to Array.At(Pistol.WeaponID, Pistol.ClipSize);

So i want to put the value at Array[0,11] to the value that is stored in Array[0,1]
so that i have a full clip again. well the first time i reload it does exactly this.

But its doing something else (too)... My Programm is setting Pistol.currentAmmo to "1" (thats the index of Pistol.ClipSize)

Why?
If u have any questions to understand my issue please let me know.
Thx
B
6
S
1
Posts: 30
Reputation: 1,059

Post » Thu Jul 31, 2014 12:18 pm

Are you able to post a .capx?

You might be using your array indices around the wrong way (confusing X for Y). Also make sure both Width and Height of the array are set correctly. Why are you jumping from using array Y index 1 (clip) to index 11 (ammo)? And remember C2 is silent about incorrectly used Arrays..
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Jul 31, 2014 12:50 pm

CAPX
https://dl.dropboxusercontent.com/u/108480585/wt.capx
Array Width is 4 and Array Height is 12

so its like Array(4, 12) right?
first row stats for weapon "0" -->Pistol
second row stats for weapon "1" --> MP
third row stats for weapon "2" --> Shotgun
fourth row game stats like cash, level etc.

I use different "Y-Index" cause in Array[X,1] it has the value for the clipsize for the Xth Weapon
and in Array[X,11] it has the value of the current amount of Bullets in the Xth Weapon mag

So my Pistol Clipsize ( Array[0,1] is of size 6 (so if i reload that weapon, i need to know how many bullets i get to fire away)

If there are problems understanding my code. let me know
Last edited by Naxos84 on Thu Jul 31, 2014 12:55 pm, edited 1 time in total.
B
6
S
1
Posts: 30
Reputation: 1,059

Post » Thu Jul 31, 2014 12:54 pm

Ok in your first post you said width is 12 which didn't sound right.

To save a .capx, choose "save as single file".
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Jul 31, 2014 12:58 pm

Obviously i mixed them up :(
But "Array Width is 4 and Array Height is 12" now is correct. (At least thats what C2 says :D )
B
6
S
1
Posts: 30
Reputation: 1,059

Post » Thu Jul 31, 2014 1:28 pm

In event 31, 32, 33 you're changing pistol.currentAmmo. This is supposed to always remain 11. You should change the array value instead.

Edit: I would make those index values global constants so you can't make this mistake again. You're repeating them in each weapon type anyway. If you had the paid version you could use family instance variables (but they are not constant).
Last edited by codah on Thu Jul 31, 2014 1:32 pm, edited 1 time in total.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Thu Jul 31, 2014 1:30 pm

Yepp....
Just found that error on my own right now.....
i didnt see that "+" in front of event 30 and thought thats it ^^^
Sorry
AND BIG THANK YOU

EDIT: yes now everything works fine so far :D
B
6
S
1
Posts: 30
Reputation: 1,059

Post » Thu Jul 31, 2014 1:33 pm

Yes exactly I didn't see those lines at first either :|
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596


Return to How do I....?

Who is online

Users browsing this forum: RandomlyMooN and 10 guests