Question about 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
BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Question about variables

#1 Post by BadRos »

Hello to everyone im new about all of this and i have a problem, so i want to know how a variable (HLSW starts with 0,75 value) can be used, i searched for two days and i tried a lot of things but im doing something wrong, it give me errors.

Code: Select all

define KO = Character ("KO_001")
default HLSW = 0,75
screen HLSW_screen():
    frame:
        align(1.0, 0.0)
        text "HLSW: [HLSW]"
# FIRST LABEL

label start:
    show screen HLSW_screen()
    "HLSW"
    $ HLSW = 0,75
    scene bgblack
    show ximage
    "{size=+20}{b}Team TEXTOOOOO{/b}{/size}"
    jump test_1
label test_1:
    GSS "TEST 1"
    jump test_2
label test_2:
    GSS "TEST 2"
    menu:
        "TEST 1":
            jump test_1
        "FIRST TOURNAMENT":
            jump first_tournament
        "FIRST TOURNAMENT 2":
            if HLSW < (0,10):
                jump first_tournament
            elif $ HLSW > (3,0):
                return
            else:
                $ HLSW += 0,50
                jump test_2
        "FIRST TOURNAMENT 3":
            $ HLSW += 1,0
            jump test_2
        "MENO TEST":
            $ HLSW -= 0,25
            jump test_2
Error

Code: Select all

[code]
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 51, in script
    if HLSW < (0,10):
SyntaxError: invalid syntax (game/script.rpy, line 53)

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 51, in script
    if HLSW < (0,10):
  File "C:\Users\Sabrin\Desktop\bad\renpy-7.1.3-sdk\renpy\ast.py", line 1762, in execute
    if renpy.python.py_eval(condition):
  File "C:\Users\Sabrin\Desktop\bad\renpy-7.1.3-sdk\renpy\python.py", line 1942, in py_eval
    code = py_compile(code, 'eval')
  File "C:\Users\Sabrin\Desktop\bad\renpy-7.1.3-sdk\renpy\python.py", line 674, in py_compile
    raise e
SyntaxError: invalid syntax (game/script.rpy, line 53)

Windows-8-6.2.9200
Ren'Py 7.1.3.1092
THE TOURNAMENT TEST VERSION 
Fri Dec 28 16:31:28 2018
[/code]
Thanks to everyone

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Question about variables

#2 Post by Remix »

In python, a tuple is considered as immutable so you would get unexpected results from your $ HLSW += 0,50 line, you'd basically get 0,75 as a tuple plus 0,50 as another tuple added to make a new tuple (0,75,0,50) and reassigned to the variable. You would not get (0,125) or (1,25) as you might want (though the 1,25 version would be easy enough if you defined your value as a float 0.5 using a period/dot rather than comma.

Your error though likely comes from using < (0,10): in Ren'Py script rather than in python. The Ren'Py parser could likely be wrapping a more informative error and just dropping it through as a SyntaxError. You'd do best just showing the console and trying the sums/calls in python and seeing what the output is. ( press Shift + O in your game window to access console )

Looking at your code though, I'd tend to suggest separating the HLSW variable into two or creating an object that uses the __add__ and __sub__ methods overloaded to support tuples, lists or just *args
A reasonably simple explanation and example of an object can be read at http://www.marinamele.com/2014/04/modif ... class.html
Frameworks & Scriptlets:

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

Re: Question about variables

#3 Post by Alex »

Code: Select all

default HLSW = 0,75
Just a thought - the decimal separator is dot (.) not a comma (,). So, if the value is not a tuple of two values 0 and 75, but 0.75, then you need to fix your numbers everywhere.

BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Re: Question about variables

#4 Post by BadRos »

https://i.imgur.com/HviN4F7.png
Like this? i changed the commas with dots, im sorry if i dont understand everithing i dont have a good english and also this is my first experience with renpy and python. Now ill go to read about _add_ method

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

Re: Question about variables

#5 Post by Alex »

Well, what value should have HLSW variable? Is it number 0.75 or tuple of two numbers 0 and 75?
If the first, then the code should look like this

Code: Select all

define KO = Character ("KO_001")
default HLSW = 0.75
screen HLSW_screen():
    frame:
        align(1.0, 0.0)
        text "HLSW: [HLSW]"
# FIRST LABEL

label start:
    show screen HLSW_screen()
    "HLSW"
    $ HLSW = 0.75
    scene bgblack
    show ximage
    "{size=+20}{b}Team TEXTOOOOO{/b}{/size}"
    jump test_1
label test_1:
    GSS "TEST 1"
    jump test_2
label test_2:
    GSS "TEST 2"
    menu:
        "TEST 1":
            jump test_1
        "FIRST TOURNAMENT":
            jump first_tournament
        "FIRST TOURNAMENT 2":
            if HLSW < 0.10:
                jump first_tournament
            elif HLSW > 3.0:
                return
            else:
                $ HLSW += 0.50
                jump test_2
        "FIRST TOURNAMENT 3":
            $ HLSW += 1.0
            jump test_2
        "MENO TEST":
            $ HLSW -= 0.25
            jump test_2

BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Re: Question about variables

#6 Post by BadRos »

I see the difference where in ",." "$" and "()", i understood the first one but im not sure about the other two, now ill try with your code corrections, and yes i need the 0.75 that can transform in 1.25, 1.70 ecc... . Thanks, sorry if i didn't reply 29/12 i wasn't in home, have a great weekend

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

Re: Question about variables

#7 Post by Alex »

Well, check the docs (if haven't yet) - there are lots of interesting things.
https://www.renpy.org/doc/html/index.html
https://www.renpy.org/doc/html/language_basics.html
https://www.renpy.org/doc/html/python.html
BadRos wrote: Sun Dec 30, 2018 8:53 am ... i wasn't in home, have a great weekend
:wink:

Post Reply

Who is online

Users browsing this forum: Wildmask