Joining Variables

DamienDamien Member Posts: 8
edited November -1 in Working with GS (Mac)
Need to know if this is possible. I want to switch images based upon a dynamic number, ie, number may change from 1-10. The images are eg. image1.png ... image10.png. What I am finding is if I have 3 global variables : pre="image", cImg=(1-10), post=".png" I cant join them together.

ie, display text = game.pre + game.cImg + game.post ==> "image3.png"

Just to clarify, its the joining of strings that doesn't work. Am I correct in this or am I being too much of a programmer?
Cheers,
:D

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    I have a health bar that changes image dependent on whether you're hit or not.

    So you have the global variable 'Lives' which is set at 10.

    If your main actor collides with another then the variable 'Lives' is put down by one.

    So in the health bar, I have the rules:

    If Lives = 10, then change image to 10.png

    If Lives = 9, then change image to 9.png

    and so on.

    Is that the kind of thing you're on about? Or have I missed the point entirely?

    Cheers,

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • DamienDamien Member Posts: 8
    Yeh, that would be one way to do it. The 1-10 was an example its actually 1-32, dont really want to use 32 rules. Much easier to say image = game.lives+".png"

    But for now, I'll use 32 rules. lol.

    Thanks,
    :D
  • FetaboyFetaboy Member, PRO Posts: 191
    I've been trying to join strings unsuccessfully as well (trying to create a keyboard for text entry). Has anyone figured this out?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    "Text"..game.Attrib..".pgf"

    Although I wouldn't suggest that as a permanent solution.
  • FetaboyFetaboy Member, PRO Posts: 191
    Thanks! That worked perfect for my on screen keyboard. I'm curious, why wouldn't you recommend it as a permanent solution? The game I'm designing requires the user to input some text. Is there a better way that I can accomplish building a string from the keys that they press?

    I'm loving this product so far. I just downloaded it this afternoon and already have a prototype up an running. I'm now leaning towards using gamesalad instead of itorque (even though I already own and know tgb).
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    It works. But you can't add spaces or multiple lines with other attributes unless the spaces and multiple lines are in other attributes first.
  • DamienDamien Member Posts: 8
    Awesome, works perfectly for what I need to do.

    QS, I'd use this for your health bar animation, save you 9 rules.

    Thanks CM.
    :D
  • CobraCobra Member Posts: 160
    It's possible to use this technique for changing between different animations as well.

    For example, a game I've been working on makes use of hand-drawn, animated numbers for displaying each digit of a score. Originally this took ten rules per actor, but I was able to cut that down to one. All I did was rename my images using numbers, for example "01.png" = the digit 0, frame 1 and "93.png" = the digit 9, frame 3, and then create a single rule per actor like this:

    Constrain Attribute [ self.Image ] to [ self.Value..game.CurrentFrame..game.ImageSuffix ]

    self.Value is the integer to be displayed;
    game.CurrentFrame is an integer that rotates from 1-3 to create the 3-frame animation;
    game.ImageSuffix is simply the text ".png"
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    As opposed to the Animate behavior?
  • CobraCobra Member Posts: 160
    Yes, exactly -- the point being that the above takes care of a _changing_ animation, e.g. a situation where I was previously using "If X, Animate using this set of images... If Y, Animate using this other set of images..." and so on.
  • quantumsheepquantumsheep Member Posts: 8,188
    "QS, I'd use this for your health bar animation, save you 9 rules."

    Sounds good to me - will revisit all my health bars at some point - cheers!

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

Sign In or Register to comment.