Hunt Payout Not Working.

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
ImperialWill
Newbie
Posts: 19
Joined: Wed Jun 29, 2016 4:19 am
Contact:

Hunt Payout Not Working.

#1 Post by ImperialWill » Thu Aug 11, 2016 4:27 am

I used an example but I still can't get it to work.

hide screen Hunts
python:
if persistent.dailyactions is not 0:
persistent.dailyactions -= 1

creditsearned = math.ceil(1000 * [huntability])

pmquote "Nice job, ! You earned [creditsearned]! Come on back and rest up; you deserve a break."

When I get to this scene, I get the following error:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/Hunts.rpy", line 20, in script
    persistent.dailyactions -= 1
  File "game/Hunts.rpy", line 24, in <module>
    pmquote "Nice job, [b]! You earned [creditsearned]! Come on back and rest up; you deserve a break."
TypeError: a float is required

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

Full traceback:
  File "game/Hunts.rpy", line 20, in script
    persistent.dailyactions -= 1
  File "C:\Users\William\Desktop\DevTools\Ren'Py\renpy-6.99.10-sdk\renpy\ast.py", line 806, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\William\Desktop\DevTools\Ren'Py\renpy-6.99.10-sdk\renpy\python.py", line 1577, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/Hunts.rpy", line 24, in <module>
    pmquote "Nice job, [b]! You earned [creditsearned]! Come on back and rest up; you deserve a break."
TypeError: a float is required

Windows-8-6.2.9200
Ren'Py 6.99.10.1227
Search for a Sister 0.0
And I haven't even got around to adding the code to make persistent.credits += [creditsearned]! Any help?!

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: Hunt Payout Not Working.

#2 Post by Iylae » Thu Aug 11, 2016 5:49 am

math.ceil returns a float, not an integer or string. If you're getting a typeerror when trying to output a string, chances are some of the parts aren't being converted.

I'm not somewhere I can test right now, but making the following change should fix this:

Code: Select all

pmquote "Nice job, [b]! You earned [str(creditsearned)]! Come on back and rest up; you deserve a break."
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

ImperialWill
Newbie
Posts: 19
Joined: Wed Jun 29, 2016 4:19 am
Contact:

Re: Hunt Payout Not Working.

#3 Post by ImperialWill » Thu Aug 11, 2016 6:09 am

Still crashing and getting this now.

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/Hunts.rpy", line 20, in script
    python:
  File "game/Hunts.rpy", line 24, in <module>
    creditsearned = math.ceil(1000*[huntability])
TypeError: a float is required

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

Full traceback:
  File "game/Hunts.rpy", line 20, in script
    python:
  File "C:\Users\William\Desktop\DevTools\Ren'Py\renpy-6.99.10-sdk\renpy\ast.py", line 806, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Users\William\Desktop\DevTools\Ren'Py\renpy-6.99.10-sdk\renpy\python.py", line 1577, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/Hunts.rpy", line 24, in <module>
    creditsearned = math.ceil(1000*[huntability])
TypeError: a float is required

Windows-8-6.2.9200
Ren'Py 6.99.10.1227
Search for a Sister 0.0
Here's the entire .rpy doc:

Code: Select all

init python:
    import math

python:
    if ParalyPlant:
        persistent.huntability += 1
    if PoisonPlant:
        persistent.huntability += 1

label Hunts:
    
    hide screen Activities
    hide screen InnActivities
    show screen Hunts
    
    $ renpy.pause(20000000, hard='True')
    
label HuntEasy:
    hide screen Hunts
    python:
        if persistent.dailyactions is not 0:
            persistent.dailyactions -= 1
            
        creditsearned = math.ceil(1000*[huntability])
            
    pmquote "Nice job, [b]! You earned [str(creditsearned)]! Come on back and rest up; you deserve a break."
    
    if actions == 2:
        jump Midday
    elif actions == 1:
        jump Evening
    elif actions == 0:
        jump Bedtime
    
label HuntModerate:
    hide screen Hunts
    python:
        if persistent.dailyactions is not 0:
            persistent.dailyactions -= 1
            
        actions = persistent.dailyactions
        
    wquote "Placeholder 2"
    
    if actions == 2:
        jump Midday
    elif actions == 1:
        jump Evening
    elif actions == 0:
        jump Bedtime
    
label HuntRisky:
    hide screen Hunts
    python:
        if persistent.dailyactions is not 0:
            persistent.dailyactions -= 1
            
        actions = persistent.dailyactions
        
    wquote "Placeholder 3"
    
    if actions == 2:
        jump Midday
    elif actions == 1:
        jump Evening
    elif actions == 0:
        jump Bedtime
huntability, and [ersistent.huntability have already been taken care of in the main script.rpy doc.

User avatar
Iylae
Regular
Posts: 73
Joined: Sat Jan 09, 2016 6:57 am
Location: Cornwall, UK
Contact:

Re: Hunt Payout Not Working.

#4 Post by Iylae » Thu Aug 11, 2016 7:07 am

Oh I've spotted it now, I feel like I've made the same mistake as you.

A square bracket around a variable converts it to a list (in python), which is what is happening to huntability here:

Code: Select all

creditsearned = math.ceil(1000 * [huntability])
So just remove the square brackets and you should be good to go:

Code: Select all

    python:
        if persistent.dailyactions is not 0:
            persistent.dailyactions -= 1
            
        creditsearned = math.ceil(1000*huntability)
            
    pmquote "Nice job, [b]! You earned [str(creditsearned)]! Come on back and rest up; you deserve a break."
Image
  If we are what we repeatedly do, then good coding is not an act, but a habit

ImperialWill
Newbie
Posts: 19
Joined: Wed Jun 29, 2016 4:19 am
Contact:

Re: Hunt Payout Not Working.

#5 Post by ImperialWill » Thu Aug 11, 2016 7:35 am

Iylae wrote:Oh I've spotted it now, I feel like I've made the same mistake as you.

A square bracket around a variable converts it to a list (in python), which is what is happening to huntability here:

Code: Select all

creditsearned = math.ceil(1000 * [huntability])
So just remove the square brackets and you should be good to go:

Code: Select all

    python:
        if persistent.dailyactions is not 0:
            persistent.dailyactions -= 1
            
        creditsearned = math.ceil(1000*huntability)
            
    pmquote "Nice job, [b]! You earned [str(creditsearned)]! Come on back and rest up; you deserve a break."
It LIVES! Thank you so very much!

Post Reply

Who is online

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