How do I make THIS work

0 favourites
  • 8 posts
  • 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)


    If u have any questions to understand my issue please let me know.


  • 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..

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Ok in your first post you said width is 12 which didn't sound right.

    To save a .capx, choose "save as single file".

  • Obviously i mixed them up

    But "Array Width is 4 and Array Height is 12" now is correct. (At least thats what C2 says )

  • 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).

  • Yepp....

    Just found that error on my own right now.....

    i didnt see that "+" in front of event 30 and thought thats it ^^^



    EDIT: yes now everything works fine so far

  • Yes exactly I didn't see those lines at first either

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)