Combining text and function
wonderiuy
Member Posts: 8
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?
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
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.
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.