Combining text and function

wonderiuywonderiuy Member Posts: 8
edited November -1 in Tech Support
I need to have an actor display a random image, ie:
I have
image1.png
image2.png
image3.png

so i presume to have a change attribure
self.image = image+random(1,3)+.png
or
self.image = "image"+random(1,3)+".png"

but nothing of above works.
Which is the correct forumula?

Comments

  • BeyondtheTechBeyondtheTech Member Posts: 809
    Because of the way GS handles its assets (you can rename Attributes and Actors on the fly and all your Behaviors and Rules will reflect the new changes - as a programmer, IMO, this is hot!) but, because of that, you have to create separate Rules to apply changes.

    If Attribute is 1, Change Image to 1
    If Attribute is 2, Change Image to 2
    If Attribute is 3, Change Image to 3

    I'm hoping there's going to be a Switch/Case function implemented soon.
  • netdzynrnetdzynr Member Posts: 296
    Maybe this is old news, but here's one way to accomplish programmatic image reference.

    Let's say you have 5 images named display1.png, display2.png, display3.png, etc.
    - Create a text attribute ImgName, set this to "display" (no quotes)
    - Create a text attribute ImgType, set this to ".png" (no quotes)
    - Create an empty text attribute ImgPath
    - Create an empty integer attribute ImgNum

    To assign a random image to an actor while running your game:
    - set the value of ImgNum to your random number: game.ImgNum = random(1,5)
    - set the value of ImgPath to game.ImgName..game.ImgNum..game.ImgType (note the double dots)
    - set the self.Image of your actor to game.ImgPath

    You actor should now be able to randomly display any imported image.
Sign In or Register to comment.