I'd like to have my software randomly select a sprite and display it on screen. On top of that, I'd like for it to repeat the process every time I click on it. My initial theory is to have the game randomly pick a number between 1 and 100 (yes, that many sprites) and display the sprite associated with that number.
I got as far as having the game select a random number, but I'm having trouble implementing it without coding elif number = 1, elif number = 2, etc. in each clickable item that will feature this function. With how flexible ren'py is, I'd like to know if there's a much simpler code I could use without having to go into the tedious work that I may have to fall back on.
Displaying a random sprite
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
- CainVoorhees
- Regular
- Posts: 45
- Joined: Sun Feb 03, 2013 2:34 am
- Soundcloud: peterjiangvo
- Contact:
Re: Displaying a random sprite
You can use eitherwhere you can set "my_var" to a file name or a displayable, or python equivalent of show statement
http://www.renpy.org/doc/html/displayin ... -statement
http://www.renpy.org/doc/html/statement ... ing-images
Code: Select all
show expression my_var
Code: Select all
$ renpy.show(my_var)
http://www.renpy.org/doc/html/statement ... ing-images
Re: Displaying a random sprite
The choice statement selects randomly an option for display:
http://www.renpy.org/doc/html/atl.html#choice-statement
And if you want to know which image is displayed, you can try showing, but it might not work with ATL:
http://www.renpy.org/wiki/renpy/doc/ref ... py.showing
http://www.renpy.org/doc/html/atl.html#choice-statement
And if you want to know which image is displayed, you can try showing, but it might not work with ATL:
http://www.renpy.org/wiki/renpy/doc/ref ... py.showing
- CainVoorhees
- Regular
- Posts: 45
- Joined: Sun Feb 03, 2013 2:34 am
- Soundcloud: peterjiangvo
- Contact:
Re: Displaying a random sprite
I feel like this is what I'm looking for, but I don't understand how I might install it. Although I looked at the tutorial and compared the script, I think I need further explanation as to how one works with ATL in python.><320amai wrote:The choice statement selects randomly an option for display:
http://www.renpy.org/doc/html/atl.html#choice-statement
The game is set up on a image map with hotspots. If you click on the "char01" hotspot, a random sprite is supposed to appear in place of the hotspot. I have it set up to when you click on the hotspot, the game selects a random number. Only problem is, the engine doesn't recognize numbers as names.
Code: Select all
label game:
scene bg starswirl
$ result = renpy.imagemap("images/whowouldwin-mockup.png", "images/cdef.jpg", [
#character
(120, 127, 360, 477, "char01"),
(600, 127, 840, 477, "char02"),
])
if result == "char01":
$ char01_roll = renpy.random.randint(1, 8)
show expression char01_roll at left with dissolve
jump game
elif result == "char02":
$ char02_roll = renpy.random.randint(1, 8)
show expression char02_roll at right with dissolve
jump game
Code: Select all
image c1 = "images/c001.jpg"
image c2 = "images/c002.jpg"
image c3 = "images/c003.jpg"
image c4 = "images/c004,jpg"
image c5 = "images/c005.jpg"
image c6 = "images/c006.jpg"
image c7 = "images/c007.jpg"
image c8 = "images/c008.jpg"
image c9 = "images/c009.jpg"
image c10 = "images/c010.jpg"
I also eventually want to set it up so that the program can record which sprites were selected and be able to display those later, but it's one of those "if I have the time" goals.
Re: Displaying a random sprite
One can use the choice statement in the init block:CainVoorhees wrote:I feel like this is what I'm looking for, but I don't understand how I might install it. Although I looked at the tutorial and compared the script, I think I need further explanation as to how one works with ATL in python.
Code: Select all
init:
$ num = 2
image somePicture 0 = "c1.png"
image somePicture 1 = "c2.png"
image somePicture anotherName:
"somePicture 1"
image somePicture rand:
choice:
"somePicture 0"
choice:
"somePicture anotherName"
init python:
def showRandom():
randomNumber = renpy.random.randint(0, num-1)
renpy.show("somePicture " + str(randomNumber))
return
label start:
show somePicture rand
"..."
hide somePicture
$ showRandom()
"..."
hide somePicture
In the code above I changed integer into string and used the function mentioned by Alex. Perhaps you could use in your code:CainVoorhees wrote:Only problem is, the engine doesn't recognize numbers as names.
Code: Select all
$ char01_roll = "c" + str(renpy.random.randint(1, 8))
show expression char01_roll at left with dissolve
Who is online
Users browsing this forum: Ahrefs [Bot]