Now I could be completely out of line, and I'm just missing something obvious, but here's the thing.
The loop inside the fight function appears to repeat an additional time.
The condition says run while the value is higher than 0
Initially the value is 1 and during each iteration it's reduced by .1
So far so good, but it does not stop once the value reaches 0
The loop breaks only after the value reaches -.1
Further more, the problem does not exist if you scale up the values, hp to 10 and the decrease to 1, which leads me to believe the condition of the while loop is not resolved correctly when dealing with float.
A last minute test indicates that the problem is resolved if hp is 2 and the condition is changed to >1
The fact that the function call is in a python block might have something to do with it.
Oh, and the Rne'py version is 6.18.3
As a matter of fact earlier I had a problem where instead of 0 the string would show some random number.
Then the code was:
Code: Select all
renpy.say("", "Hit! " +str(b.hp))Code: Select all
renpy.say("", "Hit! (%f)" %b.hp)But perhaps internally the value is still messed up which confuses the actual comparison.
Code: Select all
# You can place the script of your game in this file.
#define Combatants=[]
init python:
class combatant:
name=""
hp=1
strength=1
endurance=1
dexterity=1
agility=1
def fight(a,b):
while b.hp>0:
if a.dexterity*renpy.random.random() > b.agility*renpy.random.random():
b.hp-=.1
renpy.say("", "Hit! (%f)" %b.hp)
else:
renpy.say("", "Miss!")
return renpy.random.choice([a,b])
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
# Declare characters used by this game.
define Player = "???"
# The game starts here.
label start:
python:
Combatants=[]
i=0
while i<10:
Combatants += [combatant()]
Combatants[i].name=str(i)
i+=1
# "[Combatants]"
Player "Ah, the arena... finally. Let's see where this gets me."
python:
result=fight(Combatants[0],Combatants[1])
"[result.name]"
return
