Page 1 of 1
Can I call a label using a variable?
Posted: Sat Jul 20, 2019 10:49 am
by bdaywans
This seemed like a different enough topic from my other post to make it separate but I'm trying to call a label based on some variables. I thought that I could use [] but since I don't know renpy, I learned that was wrong fast.
Hers the long and short: During a minigame I want to call in cutcenes. So for example after round 1 it will call
Code: Select all
label win1:
"text goes here..."
return
But based on who you're competing against I want that to change. For example, I'd want to jump specifically to"
Code: Select all
label Annette_win1:
"text goes here..."
return
So that I don't have to write a game for each character/game I though it made sense to call the label using variables... for example:
Code: Select all
# before the game
$ challenger = Annette
# Then durning the game
...
label won_the_round:
"You win"
$ roundsWon += 1
call [challenger]_win[roundsWon]
jump game
# and what I'd be calling
label Annette_win1:
"some text here, blah blah..."
return
label Annette_win2:
"some text here, blah blah..."
return
But clearly this is wrong. Any I coding it incorrectly or is what I'm trying to do not possible?
Re: Can I call a label using a variable?
Posted: Sat Jul 20, 2019 2:43 pm
by Scribbles
Code: Select all
call expression my_variable + "_labelname"
you want to add expression, and don't use the []'s
Re: Can I call a label using a variable?
Posted: Sat Jul 20, 2019 7:22 pm
by bdaywans
Scribbles wrote: ↑Sat Jul 20, 2019 2:43 pm
Code: Select all
call expression my_variable + "_labelname"
you want to add expression, and don't use the []'s
Thanks! So does that mean if I was calling a label like my above example it would be:
or if I had multiple expressions (say the win number changed) I could do:
Code: Select all
call expression Annette + "_win" + roundNumber
Sorry, just trying to see if I get the idea correctly...
EDIT: I added the code in teh style I was proposing above and got an error when I called my first variable:
Code: Select all
call expression challenger + "_" + match + "_intro"
It says challenger is not defined but I have a default value set for it:
and just before its called in my script I set:
... did I break something?
Re: Can I call a label using a variable?
Posted: Sat Jul 20, 2019 9:31 pm
by damonRuru
i am sorry if i sound rude but isn't this thread is posted on the wrong section?
this section is only for completed game, you should post question here:
Ren'Py Questions and Announcements
Re: Can I call a label using a variable?
Posted: Sun Jul 21, 2019 12:18 am
by bdaywans
damonRuru wrote: ↑Sat Jul 20, 2019 9:31 pm
i am sorry if i sound rude but isn't this thread is posted on the wrong section?
this section is only for completed game, you should post question here:
Ren'Py Questions and Announcements
cr@p... you're right...
I went to the wrong category. Can I delete my post?
Re: Can I call a label using a variable?
Posted: Sun Jul 21, 2019 10:31 am
by Scribbles
hopefully a mod will move it (i didn't even notice)
call expression allows you to pass variables, it will combine all the info into a string and will call that so...
Code: Select all
default challenger = "anne"
default round = 5
# str() converts the int variable into a string -- I don't know if call expression will convert variables into strings for you
call expression challenger + "_round_" + str(round)
## would call this:
label anne_round_5:
#stuff
return
your code
Code: Select all
##i'm placing variables here since I don't know what yours are
default challenger = "anne"
default match = "match1"
call expression challenger + "_" + match + "_intro"
## would call this:
label anne_match1_intro:
#stuff
return