Variable Calls: are they strings or ???

This forum is currently in read-only mode.
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • I'm trying to set an X coordinate using a private variable call:

    Sex X || player1.X

    Since my game can have a few players whose player numbers are set to global variables, and I didn't want to constantly set code for all of them I tried to trick the system with something like this:

    Set X || "player"&global('XYZ')&".X"

    which didn't work so I tried

    Set X || str("player"&global('XYZ')&".X")

    which still resulted in nothing. So I'm left to assume "player1.X" is not a string but something else. And I'm also assuming that I can't trick Construct into thinking a returned string "playerXYZ.X" is the same as typing in playerXYZ.X

    (much to my chagrin )

    If you need a .cap I can whip one up, but it'll have to be through rapidshare because I can't access getdropbox through my DNS (much to my chagrin... again )

  • no

    you can't use variables in that way

    they are interpreted differently,

    and have a different syntax, 'like this', "instead of this"

    you can use arrays for this purpose

    or I would recommend using the s plugin

    which is designed to allow more logical data organization

  • Text in quotes never changes (they're called string literals). Construct will never take "text like this" and try to interpret it as an expression. You will literally be passing some text to the Set X function, which happens to say "Player1.X" or something similar. Construct will then try to convert this to a number to set the X co-ordinate, but this fails, so it gets zero.

    You basically can't dynamically create expressions. What are you actually trying to do, overall? Maybe families or some other feature is a better solution.

  • Thanks for your detailed description. It makes sense to me now.

    I have a 3 player platform game with three types of characters (A, B, C). In the player selection screen, when a player selects a character (say player 3 selects B), a global variable called BPlayerNum is set to 3.

    Then, in game, all actions for player type C has the input set to Player global('C')

    Which works great. The problem is setting the characters animation to the player sprite with the platform animation which happens every tick (always condition).

    I was trying to avoid having 9 conditions in the always condition through my entire game:

    If APlayerNum=1 then set A's animations to Player1

    If APlayerNum=2 then set A's animations to Player2

    If APlayerNum=3 then set A's animations to Player3

    If BPlayerNum=1 then set B's animations to Player1

    If BPlayerNum=2 then set B's animations to Player2

    If BPlayerNum=3 then set B's animations to Player3

    If CPlayerNum=1 then set C's animations to Player1

    If CPlayerNum=2 then set C's animations to Player2

    If CPlayerNum=3 then set C's animations to Player3

    I'm trying to make a .cap right now to make my explanation more clear.

    I'm trying to be a more elegant coder. Right now I use brute force way to much

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's a cap.

    3 player, 3 character game with character selector

    http://rapidshare.com/files/298210349/HELP01.cap.html

    Sorry it's at rapidshare but I don't know what the next best thing is besides DropBox (which doesn't work at my location, both uploading and downloading).

  • If APlayerNum=1 then set A's animations to Player1

    If APlayerNum=2 then set A's animations to Player2

    If APlayerNum=3 then set A's animations to Player3

    If BPlayerNum=1 then set B's animations to Player1

    If BPlayerNum=2 then set B's animations to Player2

    If BPlayerNum=3 then set B's animations to Player3

    If CPlayerNum=1 then set C's animations to Player1

    If CPlayerNum=2 then set C's animations to Player2

    If CPlayerNum=3 then set C's animations to Player3

    I think you may be able to make it this:

    Set A's animations to: "Player" & Global('APlayerNum')

    or.. Set A's animations to: "Player" & Object.Value('APlayerNum')

    Whatever the variable is stored on.

    And so on for B and C.

    Set B's animations to: "Player" & Global('BPlayerNum')

    Set C's animations to: "Player" & Global('CPlayerNum')

    There might be a better way to do it all around, but I can't think of anything.

    Oh, does it need to be 'always'? Can it be 'trigger once'? Or just done at the start of a layout, or something?

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