Global variables
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.
Global variables
i would like to ask how to write global variables, and is there any good tutorial links about the defining different types of variables?
- wyverngem
- Miko-Class Veteran
- Posts: 615
- Joined: Mon Oct 03, 2011 7:27 pm
- Completed: Simple as Snow, Lady Luck's Due,
- Projects: Aether Skies, Of the Waterfall
- Tumblr: casting-dreams
- itch: castingdreams
- Location: USA
- Contact:
Re: Global variables
Do you mean for use in python blocks or just in the script themselves?
Re: Global variables
i am sorry that i have not written clearly at the first statement, i would like to know how to use on python blocks
- isobellesophia
- Miko-Class Veteran
- Posts: 979
- Joined: Mon Jan 07, 2019 2:55 am
- Completed: None
- Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
- Organization: Friendly Teachers series
- Deviantart: SophBelle
- itch: Child Creation
- Location: Philippines, Mindanao
- Contact:
- wyverngem
- Miko-Class Veteran
- Posts: 615
- Joined: Mon Oct 03, 2011 7:27 pm
- Completed: Simple as Snow, Lady Luck's Due,
- Projects: Aether Skies, Of the Waterfall
- Tumblr: casting-dreams
- itch: castingdreams
- Location: USA
- Contact:
Re: Global variables
isobellesophia has a good starting point. If you want to know more about using variables with Python read this. https://www.renpy.org/doc/html/quicksta ... statements
If you're familiar with creating your own functions in python. You'll want to use a global variable in a function you just put global in front of it. For example;
Code: Select all
init python:
def myfunc(the_time):
global player_name
gettings = "Hello " + str(player_name) + "The time is" + str(the_time) + "right now."
return greetings
default player_name = 'Nadine'
label start:
$ game_greets = myfunc(10)
"[game_greets]"
return
- isobellesophia
- Miko-Class Veteran
- Posts: 979
- Joined: Mon Jan 07, 2019 2:55 am
- Completed: None
- Projects: Maddox and Friends! (AI Teacher friend), Friendly Universities! (Soon)
- Organization: Friendly Teachers series
- Deviantart: SophBelle
- itch: Child Creation
- Location: Philippines, Mindanao
- Contact:
Re: Global variables
If you want to use a "init python", it is a good use for any functions and classes, umfortunately, i dont use "init python" alot but its also good (i just copy those out of nowhere.), even "python". Especially variables.
Re: Global variables
wyverngem wrote: ↑Mon Mar 11, 2019 6:25 pmisobellesophia has a good starting point. If you want to know more about using variables with Python read this. https://www.renpy.org/doc/html/quicksta ... statements
If you're familiar with creating your own functions in python. You'll want to use a global variable in a function you just put global in front of it. For example;
Code: Select all
init python: def myfunc(the_time): global player_name gettings = "Hello " + str(player_name) + "The time is" + str(the_time) + "right now." return greetings default player_name = 'Nadine' label start: $ game_greets = myfunc(10) "[game_greets]" return
Thank you for the reply, i may be i am a beginner of the programming, i would like to ask about that the reason of returning greetings, i could not find a variable of greeting in the init python function, is that a function of python?
- wyverngem
- Miko-Class Veteran
- Posts: 615
- Joined: Mon Oct 03, 2011 7:27 pm
- Completed: Simple as Snow, Lady Luck's Due,
- Projects: Aether Skies, Of the Waterfall
- Tumblr: casting-dreams
- itch: castingdreams
- Location: USA
- Contact:
Re: Global variables
No, it's one I just made up when I wrote the sample function, and returned it so that the game_greets variable I made knew what it would become. If you're brand new to it then I suggest sticking to the Renpy documentation and not worrying about Python script. At least until you got the hang of working with Renpy, because it is different then working simply in Python.
Who is online
Users browsing this forum: Bing [Bot]