Unable to raise stats or substract energy

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.
Message
Author
LiquidDarkness
Newbie
Posts: 17
Joined: Wed Feb 21, 2018 7:45 pm
Contact:

Unable to raise stats or substract energy

#1 Post by LiquidDarkness »

I've been searching everywhere, using most of nerdy vocabulary I know and came up with nothing. Like stated above, I can't raise stats but nor can I deduct energy when doing action. I thought I've followed the documents and every advice I found on the forum, but still:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/park.rpy", line 20, in script
    $player_energy-=25
  File "game/park.rpy", line 20, in <module>
    $player_energy-=25
TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'

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

Full traceback:
  File "game/park.rpy", line 20, in script
    $player_energy-=25
  File "C:\Users\M\Desktop\renpy-6.99.14.1-sdk\renpy\ast.py", line 848, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\M\Desktop\renpy-6.99.14.1-sdk\renpy\python.py", line 1812, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/park.rpy", line 20, in <module>
    $player_energy-=25
TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'

Windows-8-6.2.9200
Ren'Py 6.99.14.1.3218
S M Dating Sim 1.0
Tue Mar 06 00:06:27 2018

And the code looks like that:

Code: Select all

label park:

screen park

menu park_activities:
    "What would you like to do here?"
    "Go jogging! (-25 energy)":
        "That was some intense jogging session! Your strenght has increased by 5!"
        $us_strenght += 5
        $player_energy=-25
        jump park
    "Read some book (-25 energy)":
        "Reading is always profitable for the brain! Your knowledge has increased by 5!"
        $us_knowledge += 5
        $player_energy-=25
        jump park
    "Pick up the polluting trash! (-25 energy)":
        "You spend some time on cleaning the park! Your goodness has increased by 5!"
        $us_good += 5
        $player_energy-=25
        jump park
    "Nothing":
        jump tokyo_city
This stops me from doing literrally anything and I'm a total noob, as you can see, so please, go easy on me and explaaaain what do I do wrooong? (;へ:)

In case that's needed, here goes a part with the stats definition.

Code: Select all

define player_energy = "Energy"
define player_energy_min = 0
define player_energy_max = 100
if player_energy = 0:
    "You need to go to sleep, you have no energy left!"

default us_beauty = 5
default us_good = 7
default us_knowledge = 3
default us_strenght = 4
default us_beauty_max = 1000
default us_good_max = 1000
default us_knowledge_max = 1000
default us_strenght_max = 1000

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Unable to raise stats or substract energy

#2 Post by Imperf3kt »

Your error is pointed out in the traceback:
$player_energy=-25
This is the wrong way around.
The jogging action is where you slipped up. Change it to this (like your others)
$player_energy -= 25
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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: Unable to raise stats or substract energy

#3 Post by Remix »

define player_energy = "Energy"
...
ok, so player_energy is a string (unicode)
...
$ player_energy -= 25
...
unicode string minus 25 ... hmmm, error perhaps?
Frameworks & Scriptlets:

LiquidDarkness
Newbie
Posts: 17
Joined: Wed Feb 21, 2018 7:45 pm
Contact:

Re: Unable to raise stats or substract energy

#4 Post by LiquidDarkness »

Thank you for such a prompt reply! ( ^∇^)

I still encounter the same error, though.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/park.rpy", line 15, in script
    $player_energy -= 25
  File "game/park.rpy", line 15, in <module>
    $player_energy -= 25
TypeError: unsupported operand type(s) for -=: 'unicode' and 'int'
Is there any possibility that I have made a mistake somewhere else?

HansBr
Newbie
Posts: 9
Joined: Tue Mar 06, 2018 5:10 pm
Deviantart: HansBr
Contact:

Re: Unable to raise stats or substract energy

#5 Post by HansBr »

Is player_energy still a string?
You can examine your variables before you make a menu choice with <shift>-D
Should be a number, not a string like "Energy".

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Unable to raise stats or substract energy

#6 Post by Imperf3kt »

As noticed by Remix, you have defined 'player_energy' as a string, but later edit it as if it were an integer.

To put it simpler, you have written:
Energy -25 where 'Energy' = 100
Instead of
100-25
And it is confusing Ren'Py. You cannot subtract 25 from 'Energy' because 'Energy' is a word, not a number.

Change your default player_energy to a numerical value.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

LiquidDarkness
Newbie
Posts: 17
Joined: Wed Feb 21, 2018 7:45 pm
Contact:

Re: Unable to raise stats or substract energy

#7 Post by LiquidDarkness »

Ok, so I don't get the error screen anymore, which is good. ( ^∇^)

But.
The energy level is supposed to get lower with the activities and it does not, neither do the stat raise.

HansBr
Newbie
Posts: 9
Joined: Tue Mar 06, 2018 5:10 pm
Deviantart: HansBr
Contact:

Re: Unable to raise stats or substract energy

#8 Post by HansBr »

How do you determine that these variables do not change? Do you have them displayed anywhere?
Maybe it's just the display code that is constant.
Or do you check them in any other way?

LiquidDarkness
Newbie
Posts: 17
Joined: Wed Feb 21, 2018 7:45 pm
Contact:

Re: Unable to raise stats or substract energy

#9 Post by LiquidDarkness »

I gave the player a 100 energy points and each activity was supposed to take 25 energy points away, so after choosing any four times I should see an information that I've ran out of energy. And about the stats- I found a thread on the cookbook part of the forum about displaying stats in the easiest way, and that's the code:

Code: Select all

default stat_1 = us_good
default stat_2 = us_beauty
default stat_3 = us_strenght
default stat_4 = us_knowledge

screen control:
    frame:
        xalign 0.02
        yalign 0.02
        textbutton "Stat Box" action If(renpy.get_screen("stat_box"), Hide("stat_box"), Show("stat_box"))

screen stat_box:
    frame:
        align (0.5,0.5)
        vbox:
            text "Goodness: [stat_1]"
            text "Beauty: [stat_2]"
            text "Strenght: [stat_3]"
            text "Knowledge: [stat_4]"
My problem might seem ridiculous to the more advanced programmers, I'm aware of that, but the only reason I started the subject is because I couldn't find the answer elsewhere.

LiquidDarkness
Newbie
Posts: 17
Joined: Wed Feb 21, 2018 7:45 pm
Contact:

Re: Unable to raise stats or substract energy

#10 Post by LiquidDarkness »

I now know how to raise them stats, hurray. But the energy thingy remains a mystery to me.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Unable to raise stats or substract energy

#11 Post by Imperf3kt »

Without limiting the energy to 0, you can continue to subtract from energy until you are well into the negatives.

A simple way to avoid this: (add to your menu choices)

Code: Select all

    if player_energy =>25: # may be >=
        $ player_energy -= 25
        # your action here
    else:
        "Damn, I'm beat. I haven't got the energy to do that right now."
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

HansBr
Newbie
Posts: 9
Joined: Tue Mar 06, 2018 5:10 pm
Deviantart: HansBr
Contact:

Re: Unable to raise stats or substract energy

#12 Post by HansBr »

In your initial code snipped it seems to me you check the energy at the beginning of your code, then never again.
Try checking before you change, as Imperf3kt told, or if you want to check less often at an appropriate more central place. For example at the beginning or end of your park_activities block.

LiquidDarkness
Newbie
Posts: 17
Joined: Wed Feb 21, 2018 7:45 pm
Contact:

Re: Unable to raise stats or substract energy

#13 Post by LiquidDarkness »

Ok, so I've done that:

Code: Select all

    "What would you like to do here?"
    "Go jogging! (-25 energy)":
        if player_energy =>25: # may be >=
        $ player_energy -= 25
        "That was some intense jogging session! Your strenght has increased by 5!"
        $stat_3 += 5
        $player_energy -= 25
        jump park
    else:
        "Damn, I'm beat. I haven't got the energy to do that right now."
        jump park
and this happens:

Code: Select all

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


File "game/park.rpy", line 8: if statement expects a non-empty block.
    if player_energy =>25: 
                           ^

File "game/park.rpy", line 14: expected menuitem
    else:
    ^

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Unable to raise stats or substract energy

#14 Post by Imperf3kt »

You have some indentation mismatches.
Try this:

Code: Select all

    "What would you like to do here?"
    "Go jogging! (-25 energy)":
        if player_energy =>25:
            "That was some intense jogging session! Your strenght has increased by 5!"
            $stat_3 += 5
            $player_energy -= 25
            jump park
        else:
            "Damn, I'm beat. I haven't got the energy to do that right now."
            jump park
            
Last edited by Imperf3kt on Tue Mar 06, 2018 8:17 pm, edited 2 times in total.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

LiquidDarkness
Newbie
Posts: 17
Joined: Wed Feb 21, 2018 7:45 pm
Contact:

Re: Unable to raise stats or substract energy

#15 Post by LiquidDarkness »

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/park.rpy", line 8, in script
    if player_energy =>25:
SyntaxError: invalid syntax (game/park.rpy, line 8)


Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot]