Global variables

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
db180
Newbie
Posts: 3
Joined: Sun Mar 10, 2019 9:51 am
Contact:

Global variables

#1 Post by db180 »

i would like to ask how to write global variables, and is there any good tutorial links about the defining different types of variables?

User avatar
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

#2 Post by wyverngem »

Do you mean for use in python blocks or just in the script themselves?

db180
Newbie
Posts: 3
Joined: Sun Mar 10, 2019 9:51 am
Contact:

Re: Global variables

#3 Post by db180 »

i am sorry that i have not written clearly at the first statement, i would like to know how to use on python blocks

User avatar
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

#4 Post by isobellesophia »

I am a friendly user, please respect and have a good day.


Image

Image


User avatar
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

#5 Post by wyverngem »

db180 wrote: Mon Mar 11, 2019 3:44 am 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 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

User avatar
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

#6 Post by isobellesophia »

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.
I am a friendly user, please respect and have a good day.


Image

Image


db180
Newbie
Posts: 3
Joined: Sun Mar 10, 2019 9:51 am
Contact:

Re: Global variables

#7 Post by db180 »

wyverngem wrote: Mon Mar 11, 2019 6:25 pm
db180 wrote: Mon Mar 11, 2019 3:44 am 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 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?

User avatar
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

#8 Post by wyverngem »

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.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]