Can I call a label using a variable?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Post Reply
Message
Author
bdaywans
Newbie
Posts: 15
Joined: Sat Jul 13, 2019 2:54 pm
Contact:

Can I call a label using a variable?

#1 Post 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?

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Can I call a label using a variable?

#2 Post by Scribbles »

Code: Select all

call expression my_variable + "_labelname"
you want to add expression, and don't use the []'s
Image - Image -Image

bdaywans
Newbie
Posts: 15
Joined: Sat Jul 13, 2019 2:54 pm
Contact:

Re: Can I call a label using a variable?

#3 Post 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:

Code: Select all

call expression Annette + "_win1"
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:

Code: Select all

default challenger  = "npc"
and just before its called in my script I set:

Code: Select all

$ challenger = "npc1 "

... did I break something?

User avatar
damonRuru
Newbie
Posts: 20
Joined: Sun Oct 14, 2018 12:31 pm
Contact:

Re: Can I call a label using a variable?

#4 Post 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
I am lurking behind every corner of the world just to seek one special spice for my life.

bdaywans
Newbie
Posts: 15
Joined: Sat Jul 13, 2019 2:54 pm
Contact:

Re: Can I call a label using a variable?

#5 Post 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?

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Can I call a label using a variable?

#6 Post 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
    
    
Image - Image -Image

Post Reply

Who is online

Users browsing this forum: Google [Bot], IrisColt