[Solved]Logic statements in Screens

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
EchoEcho
Newbie
Posts: 13
Joined: Tue Apr 30, 2019 3:50 am
Projects: WAI WAI, Kingdom of Castille
Location: USA/CHINA
Contact:

[Solved]Logic statements in Screens

#1 Post by EchoEcho »

Hey y'all.

So I'm working with imagemaps and stuff, and I have a system where you collect wood to build a house. I would like pieces of wood to stack up in accordance with how much actual wood you have in your inventory.

That said, I have the screen in an imagemap, but I do not want to have millions of pictures with each permutation of building level, wood amount, time of day, blah blah blah.

I have been trying to have the imagemap as a foundation of sorts, with a single log as the image, just repeating with a counter for each piece of wood.

In order to do this, I have been trying to set it where the screen with the imagemap contains a "While" statement as such:

Code: Select all

screen ext_screen:
    imagemap:
        ground "Exterior_[house_progress]_[daynight]_ground.jpg"
        idle "Exterior_[house_progress]_[daynight]_idle.jpg"
        hover "Exterior_[house_progress]_[daynight]_hover.jpg"

        hotspot (970, 407, 614, 502) action Jump("house_label")
        hotspot (8, 315, 817, 315) action Jump("forest_label")
        hotspot (675, 905, 106, 98) action Jump("building")
    $ wood_x = 505
    $ wood_y = 886
    while wood_counter <= wood:
        if wood_counter == 7:
            $ wood_y = 860
            $ wood_x = 510
        if wood_counter == 12:
            $ wood_y = 834
            $ wood_x = 515
        show "log.png" at pos(wood_x, wood_y)
        $ wood_counter -= 1
        $ wood_x += 10
However, that spits out this error message

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 103: u'while' is not a keyword argument or valid child for the screen statement.
    while wood_counter <= wood:
         ^

Ren'Py Version: Ren'Py 7.2.2.491
Thu Jun 24 17:57:48 2021
I'm at a bit of a loss as to how to get this done. Can't even get to the point where I can test the rest of the code...

If anyone can offer some advice as to how to proceed, I would be grateful.

Or maybe I'm trying this all wrong...
Last edited by EchoEcho on Mon Jun 28, 2021 1:36 am, edited 1 time in total.

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Logic statements in Screens

#2 Post by philat »

You can use a for loop in screens (but not while). It should be add, not show also.

User avatar
EchoEcho
Newbie
Posts: 13
Joined: Tue Apr 30, 2019 3:50 am
Projects: WAI WAI, Kingdom of Castille
Location: USA/CHINA
Contact:

Re: Logic statements in Screens

#3 Post by EchoEcho »

philat wrote: Thu Jun 24, 2021 7:05 am You can use a for loop in screens (but not while). It should be add, not show also.
Thanks for the help! Stupid question incoming:

How can I use a for loop outside of arrays? At least in getting the same effects as the why loop... The problem I'm having now is that "renpy for loop" is not very helpful in getting good search results, haha. Same problem when I was trying to recall the syntax for "xpos" and "ypos" and stuff. Looking up "renpy x y syntax" wasn't doing it for me, lol

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Logic statements in Screens

#4 Post by philat »

Code: Select all

for i in range(wood): 
   # doing stuff
is functionally equivalent to

Code: Select all

while counter < wood: 
   # doing stuff
    counter += 1

tornsoul
Regular
Posts: 29
Joined: Sat Jun 19, 2021 7:32 pm
Contact:

Re: Logic statements in Screens

#5 Post by tornsoul »

Code: Select all

while wood_counter <= wood:
can be done as

Code: Select all

for x in range(wood + 1):
x will be 0,1, ... wood

---

lol - got ninja post'ed there :-)

User avatar
EchoEcho
Newbie
Posts: 13
Joined: Tue Apr 30, 2019 3:50 am
Projects: WAI WAI, Kingdom of Castille
Location: USA/CHINA
Contact:

Re: Logic statements in Screens

#6 Post by EchoEcho »

Thanks a lot, friends! It worked! One step closer to finishing my game! You two are the best!

Post Reply

Who is online

Users browsing this forum: Bing [Bot]