Renpy Scrip Help (Syntax/logical)

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
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Renpy Scrip Help (Syntax/logical)

#1 Post by JeremyBenson » Fri May 03, 2013 5:01 am

Hey,

I'm working on a really simple battle system for my game, but having a bit of trouble.

Code: Select all

label TutorialBattle:
    
    $ DummyHP = 20
    $ DummyDef = 0
    $ DummyDmg = 0
    
    #Generate Character Initiative
        
    while DummyINI == RiouINI:
        $ DummyINI = renpy.random.randint(1, 20) 
        $ RiouINI = renpy.random.randint(1, 20)
            
        while DummyHP not<0:
            if RiouINI > DummyINI:
                menu:
                    "RiouHP: %(RiousHP)d"
                    "Attack with sword":
                        riou "Slash!!"
                   
                    "Defend":
                        riou "Defend!!"
                    
                    "Use item":
                        riou "mmm, potion"
    
    
    
    return
Thanks :) Jeremy

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#2 Post by JeremyBenson » Fri May 03, 2013 5:06 am

The problem is I'm getting variables not defined. DummyINI not defined.. I though that $ DummyINI = random number would be a declaration.

Also saying RiouINI not defined... but that's defined in my main script.... How does scope an variables work?

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#3 Post by kankan » Fri May 03, 2013 5:17 am

Because it's not defined the first time you use it :wink:

Your while loop is dependent on "DummyINI == RiouINI", but at that moment in time neither are defined at all. Ren'py and Python would both take a look at that and say, "Well, I don't remember ever seeing this variable before. Wonder what it equals?" even if your variable declaration is the line right after it. RiouINI not being defined is a bit trickier to bugcheck; perhaps you hit this label before that section of your main label?

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#4 Post by JeremyBenson » Fri May 03, 2013 6:21 am

Awesome, thanks for the speedy reply :)

well. I run my script.rpy when it loads and here's what's in the start label:

Code: Select all

 label start:
        
    #This is where the variables are going to be defined for the system:
        
    $ Denar = 0
    $ Items = []
        
    $ RiouHp = 100
    $ RiouMP = 0
    $ RiouDmg = 0
    $ RiouAtk = 0
    $ RiouDef = 0
        
    jump Search_DX
    scene black
That jump to Search_DX takes me to another label in my mission.rpy file... and from there I call the code above :)

I'm kinda confused on scope. I heard that anything declared in a label is global... but I'm not understanding why my battle script isn't picking up on RiouINI...

(Wish I was better scripter and master of oop haha... sadly I jimmy rig, and proceduralize. lol)

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#5 Post by JeremyBenson » Fri May 03, 2013 6:22 am

oh my, am I that burnt, haha.. I didn't realize I hadn't declared RiouINI in that main script...
Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#6 Post by JeremyBenson » Fri May 03, 2013 6:26 am

Okay so I edited the main script and have this...

Code: Select all

  label start:
        
    #This is where the variables are going to be defined for the system:
        
    $ Denar = 0
    $ Items = []
        
    $ RiouHp = 100
    $ RiouMP = 0
    $ RiouDmg = 0
    $ RiouAtk = 0
    $ RiouDef = 0
    $ RiouINI = 0
    jump Search_DX
    scene black
My problem now is line 18 on the battle script..

Code: Select all

label TutorialBattle:
    
    $ DummyHP = 20
    $ DummyDef = 0
    $ DummyDmg = 0
    $ DummyINI = 0
    
    #Generate Character Initiative
        
    while DummyINI == RiouINI:
        $ DummyINI = renpy.random.randint(1, 20) 
        $ RiouINI = renpy.random.randint(1, 20)
            
        while DummyHP not<0:
            if RiouINI > DummyINI:
                menu:
                    "RiouHP: %(RiousHP)d"
                    "Attack with sword":
                        riou "Slash!!"
                   
                    "Defend":
                        riou "Defend!!"
                    
                    "Use item":
                        riou "mmm, potion"
    
    
    
    return
Line 18 is this one...

Code: Select all

 while DummyHP not<0:
Is there indent or syntax error? Not sure what's on the go... Hard to hack through the doc... it's all pretty basic there :)

Also I know that code should be < or = would I write that just like that <= ?

Thanks guys :)
Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

User avatar
kankan
Regular
Posts: 80
Joined: Tue Mar 06, 2012 1:47 am
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#7 Post by kankan » Fri May 03, 2013 6:50 am

Ah, that's a syntax error. You want it to be while DummyHP is not less than zero, AKA is greater than or equal to zero, so

Code: Select all

while DummyHP >= 0:
You're right in that "not" is used to negate True/False values, but order of wording is important. If you really wanted to keep it the way you had it, it's possible to do

Code: Select all

while not DummyHP < 0:
...but it doesn't look quite as nice.

EDIT:
About the scope of variables, yes, variables in labels are global. I believe they have to be declared in order of execution though, so even if you have something defined later on down the line, it won't be usable up until that point.

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#8 Post by JeremyBenson » Fri May 03, 2013 7:06 am

Awesome :) that cleared the errors up there, thanks. I really appreciate the help... I'm getting a type error now...

It reads something like type error d% requires a number not unicode. I'm thinking it's caused by the following line, but not sure..

Code: Select all

"RiousHP: %(RiousHP)d"
By the way I added s' to all the variables :( I know I'm confusing haha..

so now they all read RiousHP, RiousINI, and so on...
Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

User avatar
JeremyBenson
Regular
Posts: 65
Joined: Tue Apr 30, 2013 10:46 am
Projects: Fallen
Organization: Terra Byte Studios
Location: Quebec City
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#9 Post by JeremyBenson » Fri May 03, 2013 7:08 am

Ops I got it. Had a variable wrong...

Thanks again for all the help :)
Fallen - Current project: Developing logic for RPG mechanics.
"Abel Hayes is feeling a little inhuman."
Fledgling Startup: Terra Byte Studios.
https://www.tumblr.com/blog/terrabytestudio

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Renpy Scrip Help (Syntax/logical)

#10 Post by xela » Fri May 03, 2013 7:31 am

JeremyBenson wrote:Awesome :) that cleared the errors up there, thanks. I really appreciate the help... I'm getting a type error now...

It reads something like type error d% requires a number not unicode. I'm thinking it's caused by the following line, but not sure..

Code: Select all

"RiousHP: %(RiousHP)d"
By the way I added s' to all the variables :( I know I'm confusing haha..

so now they all read RiousHP, RiousINI, and so on...

Try

Code: Select all

"RiousHP: [RiousHP]"
Also your 'code' has some holes, but I'll assume you've just started writing it.

Code: Select all

label TutorialBattle:
   
    $ DummyHP = 20
    $ DummyDef = 0
    $ DummyDmg = 0
    $ DummyINI = 0
   
    #Generate Character Initiative
       
    while DummyINI == RiouINI:
        $ DummyINI = renpy.random.randint(1, 20)
        $ RiouINI = renpy.random.randint(1, 20)
           
        while DummyHP not<0:
            if RiouINI > DummyINI:
                menu:
                    "RiouHP: %(RiousHP)d"
                    "Attack with sword":
                        riou "Slash!!"
                   
                    "Defend":
                        riou "Defend!!"
                   
                    "Use item":
                        riou "mmm, potion"
   
   
   
    return
Like what we're doing? Support us at:
Image

Post Reply

Who is online

Users browsing this forum: Bing [Bot]