[SOLVED] ARRAY How do I check for value of an entire row?

0 favourites
  • 6 posts
From the Asset Store
Match the rows with tofus to clear the rows before you pass the cook.
  • I am planning on using an array to handle my weapon inventory, selection, and ammo for my game. I have it set up to be 6 x 3 x 1

    I am new to arrays so bare with me. As I have it set up now, I have a row setup for checking if the weapon is collected. 1 being yes and 0 being no. I was planning on using this method to make it easy to cycle through weapons.

    [attachment=1:2908ih39][/attachment:2908ih39]

    Basically I was planning this:

    Global Variable :

    selectedWeapon = ""

    OnStart:

    Set up array

    On collection of weapon add to the array & update ammo on weapon selection

    [attachment=0:2908ih39][/attachment:2908ih39]

    Weapon selection (basic)

    Cycle down

    on 1 pressed | subtract 1 from selectedWeapon

    • selectedWeapon = 1 | set selectedWeapon to 6

    Cycle Up

    on 2 pressed | add 1 to selectedWeapon

    • selectedWeapon = 6 | set selectedWeapon to 1

    On cycle check for available weapons

    Array Check for value at (0,2) = 0 | got to next weapon

    Array Check for value at (0,2) = 1 | select weapon

    Which is rather redundant to create a bunch of event to check for a value.

    My question is how do I check all of the values in the row I have designated for setting if weapon is collected?

    Thanks

  • Not sure if this answers directly, but I have a few suggestions (hope you don't mind)

    With your events 63-65, I suggest you use a mechanism like

    [quote:1pqqmjem]weapons: Value at(selectedWeapon - 1, 2) = 1

    and its action to

    [quote:1pqqmjem]gun: Set gun_type to GunNames.At(selectedWeapon)

    (GunNames is an array of the gun names) then you won't need separate code for every weapon.

    Also in that block, the second check for Value.at(4, 2) is redundant (as in, rearrange the logic)

    With the weapon number cycling, set selectedWeapon to something like [quote:1pqqmjem](selectedWeapon + 1) % 5

    General:

    Use constant values for array indexes, e.g. COLLECTED = 2, AMMO = 1, NAME = 0 then your code will be less error prone and easier to read, e.g.:

    [quote:1pqqmjem]weapons: Value at( selectedWeapon, COLLECTED) = 0

    or

    weapons: Value at( selectedWeapon, AMMO) = 0

    Finally, you might want to start your 'selected weapon' values from 0 instead of 1 to match the way arrays work. You'll find yourself doing -1 and +1 a lot, and it can be tedious and error prone.

    Anyway, to check for a value in a row, use either a System: For loop or an Array: for-each loop.

    Obviously, choose to use any or none of these, but if you're new to arrays then get into good practices from the start

  • codah

    It's not a direct answer, but rather informative, which really helps me understand. This seems like a far more elegant approach. I didn't even think to pass a variable as the value in the array due to my unconventional ordering Thank you!

    If i start my 'selected weapon' values from 0 instead of 1 to match the way arrays work, than I assume an event mechanism like this :

    [quote:1mqtm9c9]weapons: Value at(selectedWeapon - 1, 2) = 1

    would become this: ?

    [quote:1mqtm9c9]weapons: Value at(selectedWeapon, 2) = 1

    Thanks again

  • If i start my 'selected weapon' values from 0 instead of 1 to match the way arrays work, than I assume an event mechanism like this :

    [quote:2c3u09sg]weapons: Value at(selectedWeapon - 1, 2) = 1

    would become this: ?

    [quote:2c3u09sg]weapons: Value at(selectedWeapon, 2) = 1

    Thanks again

    exactly

    Basically if you arrange your values and code to suit arrays from the start, you can possibly avoid writing LOTS of code. Like an order of magnitude.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • codah

    Thank you for your help!

    https://vine.co/v/OjiLqtmuOea

  • codah

    Thank you for your help!

    https://vine.co/v/OjiLqtmuOea

    that's awesome!

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