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 » Sun Mar 10, 2019 9:53 am

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: 594
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 » Sun Mar 10, 2019 1:14 pm

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 » 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

User avatar
isobellesophia
Miko-Class Veteran
Posts: 709
Joined: Mon Jan 07, 2019 2:55 am
Projects: Maddox's Everyday Talk! (13+ Unreal version), Maddox Everyday Talk! (3+ Real-Friendly version)(Upcoming 2020)
Organization: Friendly Teachers series
itch: .......
Location: Philippines, Mindanao
Contact:

Re: Global variables

#4 Post by isobellesophia » Mon Mar 11, 2019 7:38 am

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


Working on a talking simulation game for everyone, except children.

Maddox Everyday Talk!
Is my very very main project, not contain 13 below.

Main project here viewtopic.php?f=43&t=56564
Image

User avatar
wyverngem
Miko-Class Veteran
Posts: 594
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 » 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

User avatar
isobellesophia
Miko-Class Veteran
Posts: 709
Joined: Mon Jan 07, 2019 2:55 am
Projects: Maddox's Everyday Talk! (13+ Unreal version), Maddox Everyday Talk! (3+ Real-Friendly version)(Upcoming 2020)
Organization: Friendly Teachers series
itch: .......
Location: Philippines, Mindanao
Contact:

Re: Global variables

#6 Post by isobellesophia » Tue Mar 12, 2019 2:49 am

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..


Working on a talking simulation game for everyone, except children.

Maddox Everyday Talk!
Is my very very main project, not contain 13 below.

Main project here viewtopic.php?f=43&t=56564
Image

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

Re: Global variables

#7 Post by db180 » Tue Mar 12, 2019 10:31 am

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: 594
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 » Wed Mar 13, 2019 10:48 pm

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: No registered users