[Sloved] A help for a grammar and logic problem about how write a funtion

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
deltadidirac
Regular
Posts: 123
Joined: Fri Nov 30, 2018 5:00 am
Projects: Artworks and Comics
Tumblr: deltadidirac
Deviantart: Deltadidirac67
Location: Europe
Contact:

[Sloved] A help for a grammar and logic problem about how write a funtion

#1 Post by deltadidirac » Mon Nov 04, 2019 9:02 am

Hi all,

I never wrote an algorithm or defined a function that executed commands; I will ask you then how to write.

In several games I have seen that you can do the action of closing all the screens regardless of what you are doing or where you are, by calling at the beginning of a label a function that has been created on purpose.

EXAMPLE:

Code: Select all

label garage1:
	$ hideAllScreen ()       ####     in this way all screens you was before will Hide (something like a reset)
	scene 12
	"text text text "
	jump or return...
To do this, we obviously need to define and build the function (I tried to look at what others have done, but not being a programmer I didn't understand anything)

I know that to start we write something like this:

Code: Select all

init python:
	def hideAllScreen():
	.......              #####   and here starts the commends or the operations and so on....
Let's say I have 4 screens (screen1, screen 2, screnn3, screen4) the function to be built will contain this list of names with an action that commands to hide them, in this case independently in which screen I find myself (screen2, or screen 4 ), the function will hide it anyway.

Can anyone help me by writing the function (or algorithm) based on this simple example?
Being able to see an example, I can then understand the logic with which everything is written, and then apply it to my game.

It would save me from an endless series of problems I'm having,
thanks
bye
Last edited by deltadidirac on Mon Nov 04, 2019 11:43 am, edited 1 time in total.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: A help for a grammar and logic problem about how write a funtion

#2 Post by Alex » Mon Nov 04, 2019 9:45 am

Try it like

Code: Select all

init python:
    def hide_my_screens():
        my_list = ["screen_1", "my_other_screen", "gui_screen"] # list of screen names
        # this will hide screens that are in a list
        for screen_name in my_list: # 'screen_name' is just a name of variable
            renpy.hide_screen(screen_name) # without quotes, 'cause it's a name of variable not the actual screen name

        # this will hide screens, named 'screen_0', ..., 'screen_99'
        for i in range(100): # 'i' will have value from 0 to 99
            scr_name = "screen_{}".format(i)
            renpy.hide_screen(scr_name)

label my_label:
    $ hide_my_screens()
    "?!"
https://www.renpy.org/doc/html/screen_p ... ide_screen

User avatar
deltadidirac
Regular
Posts: 123
Joined: Fri Nov 30, 2018 5:00 am
Projects: Artworks and Comics
Tumblr: deltadidirac
Deviantart: Deltadidirac67
Location: Europe
Contact:

Re: A help for a grammar and logic problem about how write a funtion

#3 Post by deltadidirac » Mon Nov 04, 2019 10:14 am

Alex wrote:
Mon Nov 04, 2019 9:45 am
Try it like

Code: Select all

init python:
    def hide_my_screens():
        my_list = ["screen_1", "my_other_screen", "gui_screen"] # list of screen names
        # this will hide screens that are in a list
        for screen_name in my_list: # 'screen_name' is just a name of variable
            renpy.hide_screen(screen_name) # without quotes, 'cause it's a name of variable not the actual screen name

        # this will hide screens, named 'screen_0', ..., 'screen_99'
        for i in range(100): # 'i' will have value from 0 to 99
            scr_name = "screen_{}".format(i)
            renpy.hide_screen(scr_name)

label my_label:
    $ hide_my_screens()
    "?!"
https://www.renpy.org/doc/html/screen_p ... ide_screen
Thanks Alex kind as always, you saved me, now I will try immediately...

bye

Post Reply

Who is online

Users browsing this forum: Ocelot