How do I get an array to work?

0 favourites
  • 2 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • I am currently making a local multiplayer game where multiple controllers will be linked to one computer (so, no online play). In this, each player will select a character, and then once all have picked, the game will begin on a new layout with the player being able to control the correct character.

    The problem I'm having is getting that information about what character was selected from the character screen to the actual game without making a ton of variables. I've been trying to use an array to do this, however, the array for whatever reason is only returning 0. Every time.

    I'm looking in debug, and the character is not being added as it should. Whenever I try to modify a value myself through debug, it just changes back to 0 again. This array is not empty either - it has 6 elements. (6*1*1)

    This here is all my code related to it.

    Does anyone know why this is happening?

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Provided the top level conditions are correct this event will run continuously every tick. I think what you want is a triggered event, or more likely a function to run this inside of.

    Hard to tell anymore looking at the code. It looks overly complex for what you are trying to describe. An array does not seem to be necessary.

    On your selection screen you could use something like:

    On gamepad 0 button (whatever your select button is) is pressed

    Pick CharacterSprite overlapping CursorSprite0

    - Set var_P1 to CharacterSprite.var_name

    On gamepad 1 button (whatever your select button is) is pressed

    Pick CharacterSprite overlapping CursorSprite1

    - Set var_P2 to CharacterSprite.var_name

    etc.

    If you don't want to store them in variables I would use a dictionary and instead of:

    - Set var_P1 to CharacterSprite.var_name use - Dictionary SetKey "P1" to CharacterSprite.var_name

    Arrays are more useful when you need to manipulate the data within them. If you just need to store values Dictionaries are much easier.

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