labels with arguments?[SOLVED]

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
User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

labels with arguments?[SOLVED]

#1 Post by TellerFarsight » Thu Sep 14, 2017 9:58 am

So I have this bit of code here, with a bunch of displayables and such, with the "arguments" of Kazuya and Kobold. I have this exact same code elsewhere, but with other "arguments" Atsuro and Kabuso. Is there a way I can store this somewhere and access it with a jump label or call label, and supply arguments to it?

Code: Select all

    hide screen turn_order
    show bg electric onlayer battle2 with fade
    show unit_turn onlayer battle3 at unit1_pos,ascend
    show unit_idle as unit_idle2 onlayer battle3 at unit2_pos,ascend2
    show unit_idle as unit_idle3 onlayer battle3 at unit3_pos,ascend2
    show enemy_idle as enemy_idle1 onlayer battle3 at enemy1_pos,descend
    show enemy_idle as enemy_idle2 onlayer battle3 at enemy2_pos,descend2
    show enemy_idle as enemy_idle3 onlayer battle3 at enemy3_pos,descend2
    show screen battle_overlay(Kazuya,Kobold)
    
    call screen your_move(Kazuya, "Kazuya", Kobold)
    
    hide unit_turn onlayer battle3
    hide enemy_idle1 onlayer battle3
    show unit_idle as unit_idle1 onlayer battle3 at unit1_pos
    show enemy_turn onlayer battle3 at enemy1_pos
    pause 1.0
    $ Kobold.attack(Kazuya)

    hide screen battle_overlay
    hide bg electric onlayer battle2
    hide unit_idle1 onlayer battle3
    hide unit_idle2 onlayer battle3
    hide unit_idle3 onlayer battle3
    hide enemy_turn onlayer battle3
    hide enemy_idle2 onlayer battle3
    hide enemy_idle3 onlayer battle3
    with fade
    show screen turn_order
Last edited by TellerFarsight on Thu Sep 14, 2017 12:33 pm, edited 1 time in total.
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: labels with arguments?

#2 Post by DannyGMaster » Thu Sep 14, 2017 11:47 am

There could be better ways to do it, but so far the simplest way I've found to accomplish this is to store each argument inside global variables, and then, pass them to the label using the call statement.

Code: Select all

default ally1 = None
default ally2 = None
default enemy1 = None
default enemy2 = None

label battle_1_prep:

    "Going to battle"
    
    $ ally1 = Kazuya #These are unit or fighter objects, I assume
    
    $ ally2 = Atsuro
    
    $ enemy1 = Kobold
    
    $ enemy2 = Kabuso

    call battle_test(ally1, enemy1) 

    "Test end."

    return

label battle_test(arg1, arg2): 

    "I was called, the values are: [arg1], [arg2]" #Used this to test if the arguments are being passed
    
    show screen battle_overlay(arg1, arg2) #How you would call the screen using the arguments provided to the label
    
    # And the rest of the code would follow here
    
The silent voice within one's heart whispers the most profound wisdom.

User avatar
TellerFarsight
Veteran
Posts: 230
Joined: Sun Jun 04, 2017 8:09 pm
Projects: Vora, Secrets Untold
Location: Toronto, ON
Contact:

Re: labels with arguments?

#3 Post by TellerFarsight » Thu Sep 14, 2017 12:32 pm

Just what I was looking for. Thanks!
Current Project: Vora
Also Check Out: Devil Survivor [Reverse-Engineered]

Post Reply

Who is online

Users browsing this forum: badanni, Bing [Bot], Destiny-Smasher, Kokoro Hane