VN Ren'Py Is it possible to have the game check to make sure conditions aren't true before moving to next scene?

ChaosOpen

Well-Known Member
Game Developer
Sep 26, 2019
1,013
2,128
I'm doing an S&M game, but the idea is that rather than having the user mess up once and they are done, the M/sub/bottom has a stress level which builds up if the user chooses cruel acts or goes down if they choose to be kind, plus a training level in which the M builds up a tolerance to stress. So, basically to get a bad end the user has to consistently be a dickhead because it is more of an abusive relationship at that point. That's the basic background.

What I need the game to do after every choice, check a long list of possible states of the heroine's mentality, if it checks a flag, the game diverts to a stress reaction where she lashes out against the MC, if not, then the game continues as normal. The only way I know how to do it is a giant elif list, it's high simplified and will probably be more complex when implemented in game as I balanced it more(I want to let the user have some fun but not allow them to go into psychopath levels).

So, it would look something like this and would check at the end of the scene:

Python:
    if training == 0
        if stress < 4
            $ training += 1
            jump continue_to_next_scene
        elif stress > 4
            jump stress_1_scene
        elif stress > 6
            jump stress_2_scene
        elif stress > 8
            jump stress_3_scene
    elif training == 1
        if stress < 6
            $ training += 1
            jump continue_to_next_scene
        elif stress > 6
            jump stress_1_scene
        elif stress > 8
            jump stress_2_scene
        elif stress > 10
            jump stress_3_scene
    elif training == 2
        $ training += 1
        if stress < 8
            jump continue_to_next_scene
        elif stress > 8
            jump stress_1_scene
        elif stress > 10
            jump stress_2_scene
        elif stress > 12
            jump stress_3_scene
    elif training == 3
        if stress < 10
            $ training += 1
            jump continue_to_next_scene
        elif stress > 10
            jump stress_1_scene
        elif stress > 12
            jump stress_2_scene
        elif stress > 14
            jump stress_3_scene
    elif training == 4
        if stress < 12
            $ training += 1
            jump continue_to_next_scene
        elif stress > 12
            jump stress_1_scene
        elif stress > 14
            jump stress_2_scene
        elif stress > 16
            jump stress_3_scene
EDIT: I just realized my mistake, the first time the user comes with a stress level of 4 the game is going to freak out, but pretend it works for now.

Thing is, the game is branching/linear(not a sandbox), so while I could just copy and paste the list at the end of every scene in which the user can invoke a stress reaction, I'd like to shorthand it. The only way I can think of is to have a second elif list which the game jumps to that list in which keeps track of a third variable, the scene_progress.

Python:
    if scene_progress == 1
        jump scene_1
    elif scene_progress == 2
        jump scene_2
    elif scene_progress == 3
        jump scene_3
    elif scene_progress == 4
        jump scene_4
    elif scene_progress == 5
        jump scene_5
    elif scene_progress == 6
        jump scene_6
So, at the end of the scene I can just put
$ scene_progress += 1
jump stress_level

So, you basically get the program going:

What is our training level?
- it's 2, check that list against our stress
Is stress less than 8?
-Yes, move onto label "scene_progress"
What is our scene_progress?
-It's 4, so lets go to scene_4

And the story continues at scene_4

Thing is, having a giant elif statement take you to another elif statement which takes you to a yet another elif statement sounds really inefficient.
 
Last edited:

zaemech

New Member
Sep 13, 2018
13
2
This is just a quick thought, having never used Renpy, but a fair bit of python experience.
You could have an object for each training scene, toss them all into an array. Call the appropriate training scene and when you do, pass the various modifier values (stress and whatever else you may have) to it. Potentially having a method that will map the stress levels correctly (or if it's always 2, 4, 6, 8...just divide by 2 before passing it).

so something like
Code:
class training(object):
  def __init__(self, ...): # pass variables
    stressLevel = [] # fill with stress scenes, probably should be objects themselves.
    # setup all the scenes here

  def _convStress(self, stress):
    # map the stress levels here
    ...
    return stress

  def playTraining(self, stress):
    jump stressLevel[_convStress(stress)]

def main():
  trainings = {} # a dict so you can name the scene internally. Alternatively since it's a kinetic novel, an array would work fine too.
  #setup and add trainings
  ...
  trainings['outdoors_public'].playTraining(stress)
*made a few code changes
 
Last edited:

ChaosOpen

Well-Known Member
Game Developer
Sep 26, 2019
1,013
2,128
This is just a quick thought, having never used Renpy, but a fair bit of python experience.
You could have an object for each training scene, toss them all into an array. Call the appropriate training scene and when you do, pass the various modifier values (stress and whatever else you may have) to it. Potentially having a method that will map the stress levels correctly (or if it's always 2, 4, 6, 8...just divide by 2 before passing it).

so something like
Code:
class training(object):
  def __init__(self, ...): # pass variables
    stressLevel = [] # fill with stress scenes, can be objects themselves.
    # setup the scene here

  def playTraining(self, stress):
    jump stressLevel[stress]

def main():
  trainings = {}
  #setup and add trainings
  ...
  trainings['outdoors_public'].playTraining(stressLevel) # so you can name the scene internally
So, it seems like it is possible to do it, it just seems quite a bit above my level... For example, an array, I'm not even sure what that is much less how I would set it up, plus what sets an "object" apart from anything else? I'd prefer to have it where before I implement it I understand what it is and what it is doing as opposed to just copy/pasting code. I mean, I have no problem with copy/paste, but I'd like to know what the code is actually doing.

One thing I would like to know: though it is spaghetti code, would it technically work? They won't be as evenly spaces as 2,4,6,8... I'd need to put a fair number of tweaks to match the possible stress to the number of options I want to include. For example, if the user can shouldn't be able to accrue a huge stress score if they go crazy in a single scene, the stress should be additive over multiple scenes, they shouldn't be able to max it after just going crazy once, but at the same time I don't want them watching a bunch every single time. They should be choosy on what they want to see.

Also, as far as the training, I was thinking of moving it down one level, so if they are under the minumum amount they get no change and the story continues, but if they push her just a bit, her training goes up(basically training is her building up a tolerance to it), so the user would need to give her just the right amount of pressure to get her used to it without going overboard. I want to keep the number invisible, but have the game give them subtle hints such as "she looks like she wants more," "she seems satisfied," and "I might have pushed her too far."

Though at that point, we run into a problem of having to create an entirely different list for each scene... I would like to know if rather than jumping around it could just run a quick check. Where I tell it training is X and stress is Y, where are we at? Then it simply tells me "too little," "too much," or "just right"
 

zaemech

New Member
Sep 13, 2018
13
2
Vitalsigns said:
For example, an array, I'm not even sure what that is much less how I would set it up
Aw dude, you're missing out. Also you may know it as a list. Python calls them lists.

Code:
array = [1, "2", 3, 4, 5] # that's it
print(array[0]) # will print the integer 1
print(array[1]) # will print the string '2'

array2 = [] # this will also create an array
array2.append(1) # this will add the value of 1 to it
print(array2[0]) # prints the integer 1

#potentially more useful for renpy would be dictionaries, but are harder to setup. I can explain them if you'd like.
Vitalsigns said:
what sets an "object" apart from anything else?
My answer to this is technically correct but would draw the ire of programmers the world over. In the most basic view, an object is a program within a program. It is a named, self contained set of functions (called methods) and variables that are defined for a narrow task. So having 1 object per scene (where the object contains dialog, dialog branches, images, music. All of which may very well be their own objects) is perfectly acceptable.

Vitalsigns said:
I'd prefer to have it where before I implement it I understand what it is and what it is doing as opposed to just copy/pasting code. I mean, I have no problem with copy/paste, but I'd like to know what the code is actually doing.
I'm the same. Sometimes though I copy and paste and through messing with it I figure out what's going on.


Vitalsigns said:
One thing I would like to know: though it is spaghetti code, would it technically work? They won't be as evenly spaces as 2,4,6,8... I'd need to put a fair number of tweaks to match the possible stress to the number of options I want to include. For example, if the user can shouldn't be able to accrue a huge stress score if they go crazy in a single scene, the stress should be additive over multiple scenes, they shouldn't be able to max it after just going crazy once, but at the same time I don't want them watching a bunch every single time. They should be choosy on what they want to see.
Yeah, a large if/else block will work fine. Just expect to spend more time on debugging or tweaking/finding stuff.
On the note of acruing large amounts of something, it's entirely possible to do this:
Code:
# assuming there's a limit on a per scene basis, you could have a variable and update it every scene.
def checkStress(stress, limit):
  if stress > limit:
    stress = limit
  return stress

def main():
  #setup game
  stressLimit = 2 # default stress

  ... #game stuff

  if scene6:
    stressLimit = 18 # Make sure this is declared _outside_ of the if/else block, like I did above.
    # scene stuff
    stress += 1
    stress = checkStress(stress, stressLimit)

Vitalsigns said:
Also, as far as the training, I was thinking of moving it down one level, so if they are under the minumum amount they get no change and the story continues, but if they push her just a bit, her training goes up(basically training is her building up a tolerance to it), so the user would need to give her just the right amount of pressure to get her used to it without going overboard. I want to keep the number invisible, but have the game give them subtle hints such as "she looks like she wants more," "she seems satisfied," and "I might have pushed her too far."

Though at that point, we run into a problem of having to create an entirely different list for each scene... I would like to know if rather than jumping around it could just run a quick check. Where I tell it training is X and stress is Y, where are we at? Then it simply tells me "too little," "too much," or "just right"
Functions. Just make a function that accepts the bounding values and then just works with those numbers.

Code:
def trainingIntensity(lower, golden, upper, current):
  if current <= lower:
    # too little
  elif current >= upper:
    # too much
  else:
    # just right

# You could return say number like 0 for perfect, -1 for too low, 1 for too high and then show the appropriate text outside of the function.
# This way you can write the code once and just reuse it over and over again.
If you actually want to learn this stuff feel free to pm me. Or we can keep it here, it may be useful for others.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,265
15,074
Thing is, the game is branching/linear(not a sandbox), so while I could just copy and paste the list at the end of every scene in which the user can invoke a stress reaction, I'd like to shorthand it. The only way I can think of is to have a second elif list which the game jumps to that list in which keeps track of a third variable, the scene_progress.
I'm not really sure that I understood the process you want to achieve, but there's way to shorter everything.

Firstly, the if structure testing the stress value all follow the same structure :
Code:
if stress < X:
    $ training += 1
    jump continue_to_next_scene
elif stress > X:
    jump stress_1_scene
elif stress > X + 2:
    jump stress_2_scene
elif stress > X + 4:
    jump stress_3_scene
Side note: Like this you'll never branch to "stress_2_scene" and "stress_3_scene", because if stress is superior to "X + 4", then it's also superior to X, and it's what will be used. You need to perform the test in a descending order.

Secondly, the "X" value increase following a regular pattern :
Code:
if training == 0:
    X = Y
elif training == 1:
   X = Y + 2
elif training == 2:
   X = Y + 4
elif training == 3:
   X = Y + 6
elif training == 4:
   X = Y + 8
So, at first you can radically reduce the code you need :
Python:
    $ baseStress = 4 + ( training * 2 )
    if stress > baseStress + 4:
        jump stress_3_scene
    elif stress > baseStress + 2:
        jump stress_2_scene
    elif stress > baseStress:
        jump stress_1_scene
    elif stress <= baseStress:
         #  As your code is wrote, the /training/ is increased during the last loop.
         # Not sure if it's a bug or a feature, so I limit its value to 5, exactly like it
         # happen with your code.
         if training <= 4:
            $ training += 1
        jump continue_to_next_scene
What already lead to near to five time less lines to copy.


Then come the problem of the copy itself.
I suppose that the "stress_1_scene", "stress_2_scene", "stress_3_scene" and "continue_to_next_scene" labels are just for the example and therefore are different depending of the scene itself. Yet, with some constancy in their naming, you can avoid to have to copy your test.

For this, just use a called label, and use the value it return to branch to the next label.
Code:
label scene1:
    [content of the scene]
    call stressTest( "scene1" )
    jump expression _return

label scene1_continue:
    [whatever behind "continue_to_next_scene"]

label scene1_stress1:
    [whatever behind "stress_1_scene"]

label scene1_stress2:
    [whatever behind "stress_2_scene"]

label scene1_stress3:
    [whatever behind "stress_3_scene"]

label scene2:
    [content of the scene]
    call stressTest( "scene2" )
    jump expression _return

label scene2_continue:
    [whatever behind "continue_to_next_scene"]

label scene2_stress1:
    [whatever behind "stress_1_scene"]

label scene2_stress2:
    [whatever behind "stress_2_scene"]

label scene2_stress3:
    [whatever behind "stress_3_scene"]

label stressTest( baseLabel ):
    $ baseStress = 4 + ( training * 2 )
    if stress > baseStress + 4:
        return baseLabel + "_stress3"
    elif stress > baseStress + 2:
        return baseLabel + "_stress2"
    elif stress > baseStress:
        return baseLabel + "_stress1"
    elif stress <= baseStress:
         if training <= 4:
            $ training += 1
        return baseLabel + "_continue"
 

Diconica

Well-Known Member
Apr 25, 2020
1,092
1,138
I'm doing an S&M game, but the idea is that rather than having the user mess up once and they are done, the M/sub/bottom has a stress level which builds up if the user chooses cruel acts or goes down if they choose to be kind, plus a training level in which the M builds up a tolerance to stress. So, basically to get a bad end the user has to consistently be a dickhead because it is more of an abusive relationship at that point. That's the basic background.

What I need the game to do after every choice, check a long list of possible states of the heroine's mentality, if it checks a flag, the game diverts to a stress reaction where she lashes out against the MC, if not, then the game continues as normal. The only way I know how to do it is a giant elif list, it's high simplified and will probably be more complex when implemented in game as I balanced it more(I want to let the user have some fun but not allow them to go into psychopath levels).

So, it would look something like this and would check at the end of the scene:
...
First, off I don't use python every single day. I program mostly in C & C++
There are a number of ways to do it. One of which has already been expressed.
My suggestion to start with is spend a little time away from working on the game and just use a little time to learn a bit about python in and of itself.

You can learn a hell of a lot in a real short time that can help you greatly.
Take the code you showed with if else statements. They have a number of issues. First, the more you make use of them the worse your program will perform especially if they end up nested.
Secondly, they can become a pain in the ass to maintain.

You can however do something rather simple.
Define the functions you want to happen before hand.
Then create an array and fill it in with the function you want to be used.
Example: You might have a function called base reaction which will be used from level 0 to 4 at 5 you might want another function screaming_fit to occur so at 15 and above till the next function you fill the array with screaming_fit.
Python:
#define functions prior to this
#then build array
stress_reactions = [base,base,base,base,base,screaming_fit,screaming_fit, pissess_self] #function names are stored in array in the location appropriate for the level reaction
#to call it
stress_reactions[stress_level](...)
It will work a lot faster. You can keep related reaction near one another by creating the different functions for them.
If you want to adjust the level stuff happens its just a matter of adjusting the array position.

There is another similar method to this it uses a dictionary rather than an array.
The benefit of it is you do not need to fill in every spot of the array. You can instead just fill in the levels you want with the key you want.
That said you then need to figure out how to direct the dictionary to select the appropriate value for the out put.
Python:
stress_reactions = dict([(1,base),(5,screaming_fit),(7,pissess_self)])
#to call it
stress_reactions[stress_level](...)
You could also take these systems and put them in a object and it would allow you to use it for more than a single character. You wouldn't need to rewrite the code over for every single character. A bit more work and you could customize those arrays or dictionaries to be different for each character.

Lets take a look at the if else statements you wrote for each one of those it has to do a comparison then run the code it points to if not do a function call.
The further it has to code down the tree to find the right one the more it has to do. If they become nested then there is even more work with jumping in and out of each of the levels.
Those systems above I showed can be vastly faster.
They are also easier to read and maintain and modify.

So by spending a little bit of time researching and understanding something simple like that above you can greatly improve the way you program will run but also make it easier for you to keep track of and work on in the future.
Maybe it takes you an hour to learn but it could save you dozens of hours just in trouble shooting or rewriting code later on.

You don't have to use my specific method.

The method I showed you was similar to what a switch would do in C and C++. I chose it because you only named two parameters and it is rather simple and efficient for someone new to use.
 
Last edited:

Harkonnan

Give me chiisana oppai!
Game Developer
Oct 24, 2020
186
315
I just started working on coding in python myself for a game I'm trying to make and one of the characters is going to be shy and i was thinking of using a stress versus tolerance idea myself. I was thinking of setting values to actions to determine how much stress was added per action and adding that cumulatively and reducing a percentage based on tolerance to determine the starting variable for the next encounter. Not sure how you would code something like that yet but i am looking into it. Could this be coded easily? If so maybe a system like that could be used for your project to help streamline things for future updates.

so I guess as an example it would be something like this:

character max stress value = 15
starting value = 5


choice1 +1
choice2 +2
choice3 -1

and you do this for a couple answers so you total for this event would be say another 5 stress

so you now have a total of 10

set a value for each level of tolerance so say a base of 20% and increase for each tolerance level by say 5%

if you give this character a tolerance level of 2 then it would be 30%

so then take the 30% and reduce it from the 10 so you would get 7 and check that against the total value of the character limit of 15. so 7<15 so good go to next good event but if it goes over the 15 value you give bad end/event.

I was thinking of trying this for my game. Like I said I'm not too sure how I would code it as I'm looking into it still but if this will help you at all feel free to try it out.
 

ChaosOpen

Well-Known Member
Game Developer
Sep 26, 2019
1,013
2,128
Based on what I've learned, you may be able to do it like this:

This one you basically have your definitions: her tolerance level named "tolerance", the stress you give her named "stress", and her actual stress named stresslevel which you have the computer find in the form of an equation.

You start stress at 5 then tolerance at 2, so that when you first begin the tolerance will divide the stress it by 20% and give you her stress level. Then as her tolerance grows, at 3 it will dividie it by 30% tolerance 4 by 40% etc.
Python:
define stress = 5
define tolerance = 2
define stresslevel = stress - (stress*(tolerance * 0.1))
So, then you get to the choice, which adds to the stress
Python:
menu:
    "choice 1":
        $ stress += 1
    "choice 2"
        $ stress += 2
    "choice 3":
        $ stress -= 1
After they select, before moving onto the next scene, it runs it through the calculation and decide whether to proceed with her rejecting or accepting you.

Python:
if stresslevel < 15:
    jump positive_response
else:
    jump negative response
Let's say they chose choice #2, the game will add 2 to the stress and run through to see what the "stresslevel" is, saying 7 - (7*(2*0.2)) = 5.6
Since 5.6 is less than 15 you're on her good side and going to get a good response.

You can use that basic framework to tweak the numbers until you get her slowly learning to accept you.
 
Last edited:

zaemech

New Member
Sep 13, 2018
13
2
Let's say they chose choice #2, the game will add 2 to the stress and run through to see what the "stresslevel" is, saying 7 - (7*(2*0.2)) = 5.6
Since 5.6 is less than 15 you're on her good side and going to get a good response.

It probably doesn't matter for most visual novels (say, 1 extra/less interaction with someone), but beware that comparing floating point numbers may not always work due to rounding errors.
Quick example:
Code:
import math

ans = math.degrees(math.asin(math.acos(math.atan(math.tan(math.cos(math.sin(math.radians(9))))))))
# the result of the above _should_ be 9. But is unlikely to be 9.
# evaluated to 9.00000000000001 on my machine.

if ans == 9:
    print("True")
else:
    print("False") # should print this

# something like the following is more likely to work
# subtract the number you're comparing against (or subtract the calculated value, doesn't matter)
# get the absolute value of that
# and then compare it against a small floating point value (0.1, 0.01, etc)
if abs(ans - 9) <= 0.1:
    print("True") # should print this
else:
    print("False")

# in case you're wondering if it works for subtracting a larger number from a smaller, yes
if abs(8.92 - 9) <= 0.1:
    print("True") # should print this
else:
    print("False")
While I used a contrived example, I've seen rather innocuous math create numbers like that.
 

Diconica

Well-Known Member
Apr 25, 2020
1,092
1,138
Based on what I've learned, you may be able to do it like this:

This one you basically have your definitions: her tolerance level named "tolerance", the stress you give her named "stress", and her actual stress named stresslevel which you have the computer find in the form of an equation.

You start stress at 5 then tolerance at 2, so that when you first begin the tolerance will divide the stress it by 20% and give you her stress level. Then as her tolerance grows, at 3 it will dividie it by 30% tolerance 4 by 40% etc.
Python:
define stress = 5
define tolerance = 2
define stresslevel = stress - (stress*(tolerance * 0.1))
So, then you get to the choice, which adds to the stress
Python:
menu:
    "choice 1":
        $ stress += 1
    "choice 2"
        $ stress += 2
    "choice 3":
        $ stress -= 1
After they select, before moving onto the next scene, it runs it through the calculation and decide whether to proceed with her rejecting or accepting you.

Python:
if stresslevel < 15:
    jump positive_response
else:
    jump negative response
Let's say they chose choice #2, the game will add 2 to the stress and run through to see what the "stresslevel" is, saying 7 - (7*(2*0.2)) = 5.6
Since 5.6 is less than 15 you're on her good side and going to get a good response.

You can use that basic framework to tweak the numbers until you get her slowly learning to accept you.
Yep you can do it that way.
It won't take to long before you have a game that has a lot of lag and is very hard to trouble shoot bugs in.
While renpy makes it relatively easy to make something that is quite simple. The basic script system designed to make life for newbies isn't the most optimal thing in the world.
You are going to need to learn quite a bit more programming to make anything worth playing.
 

Harkonnan

Give me chiisana oppai!
Game Developer
Oct 24, 2020
186
315
So to make sure I understand what you guys are saying. Just don't use and percent type calculations till I get better at coding. For now do all math in simple forms(standard addition or subtraction) with whole number calculations or I may get bogged down with hard to track errors?
 
Apr 24, 2020
192
257
So to make sure I understand what you guys are saying. Just don't use and percent type calculations till I get better at coding.
I wouldn't say that you should stay away from float values, but there is the risk that two float values should be equal to each other but are different due to rounding errors.
For example, in Ren'Py when I write 0.04 - 0.03 - 0.01 I get 1.73e-18 instead of 0.

As long as you are using less than or greater than comparisons, these errors shouldn't matter too much.
If you want to directly compare two float values, you can turn them into a less than or greater than comparison by doing something like this abs(val1 - val2) <= tollerance.

You can pack it down to a standard function to make it easier to use:
Python:
init python:
    def almostEqual(val1, val2, tollerance = 1e-9):
        return abs(val1-val2) <= tollerance
Just don't be surprised if you use this val1 == val2 for float values and something breaks.
 

Harkonnan

Give me chiisana oppai!
Game Developer
Oct 24, 2020
186
315
ah ok thanks. yeah the idea was going to be <15 not ==15 my idea was that 15 would be the "breaking point" for the character and bad shit would happen. so as long as I don't go looking for exact values I could be ok. And I was only thinking of using this for one character. Thanks a lot for all your information. This will help me a great deal moving forward.
 

Diconica

Well-Known Member
Apr 25, 2020
1,092
1,138
I wouldn't say that you should stay away from float values, but there is the risk that two float values should be equal to each other but are different due to rounding errors.
For example, in Ren'Py when I write 0.04 - 0.03 - 0.01 I get 1.73e-18 instead of 0.

As long as you are using less than or greater than comparisons, these errors shouldn't matter too much.
If you want to directly compare two float values, you can turn them into a less than or greater than comparison by doing something like this abs(val1 - val2) <= tollerance.

You can pack it down to a standard function to make it easier to use:
Python:
init python:
    def almostEqual(val1, val2, tollerance = 1e-9):
        return abs(val1-val2) <= tollerance
Just don't be surprised if you use this val1 == val2 for float values and something breaks.
Funny the error in floating point shouldn't be greater than the error in precision of the mantissa in the float.
Meaning if the mantissa is accurate out to 0.000000001 that should be the greatest amount it should be off
Excluding the exponents effect on it.
You would think that CPython for example shouldn't be any less accurate than the math in C.
Just makes me wonder how the fuck a developer can fuck up this bad.
Guessing programs like blender aren't using python so much to do the math but call parts of its programs to handle it.
 

Diconica

Well-Known Member
Apr 25, 2020
1,092
1,138
So to make sure I understand what you guys are saying. Just don't use and percent type calculations till I get better at coding. For now do all math in simple forms(standard addition or subtraction) with whole number calculations or I may get bogged down with hard to track errors?
What InCompleteController said makes sense in regard to the math.

That said when it comes to flow control of the program you should know more than using IF ELSE.
If the only way you know how to control the path of a program is If Else you will end up with a nightmare of code on your hands. Then you probably won't want to fix it because it will be a daunting task. I will bet that is exactly why a lot of developers simply quit.

This is effectively a switch statement in python.
Python:
#! /usr/bin/env python

def func_0():
    print ("Function 0\n")
    
def func_1():
    print("Function 1\n")

def func_2():
    print ("Function 2\n")

def func_3():
    print ("Function 3\n")

def switch(arg):
    case = {
        0:func_0,
        1:func_1,
        2:func_2,
        3:func_3,
    }
    case[arg]()
    
i = 0
while i < 4:
    switch(i)
    i=i+1
You also might want to look at a previous post where someone posted a state machine or as they call it a state system.
https://f95zone.to/threads/class-ba...cter-attributes-and-so-on.44878/#post-2976214
It's a bit more complex than what I posted above but does have a some advantages.
I don't however think it is needed for the little bit you are discussing. But you can see from it there are more optimal ways of controlling large complex systems more efficiently.
 

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,265
15,074
Apr 24, 2020
192
257
Funny the error in floating point shouldn't be greater than the error in precision of the mantissa in the float.
Meaning if the mantissa is accurate out to 0.000000001 that should be the greatest amount it should be off
Excluding the exponents effect on it.
You would think that CPython for example shouldn't be any less accurate than the math in C.
Just makes me wonder how the fuck a developer can fuck up this bad.
Guessing programs like blender aren't using python so much to do the math but call parts of its programs to handle it.
I'm not a computer science guy, so I'm certain the 1e-9 tolerance is too wide, compared to what is possible. I just pulled a number that seemed reasonable, given the examples mentioned just had a few digits after the decimal point.
 
  • Like
Reactions: Diconica