HTML Twine/Sugarcube Math

DickJustice

New Member
May 17, 2018
14
11
So, recently, I decided to get back to sugarcube development and I feel like I'm going insane.

For some reason, math within the game either works or doesn't work based on some arcane ever-shifting rule. One variable is updating normally, the one right after it refuses to register any change. I tried googling my exact problem and motoslave docs aren't really helpful.

The issue is:

I want one variable to be a result of adding up a fraction of another variable. At first it returned NaN but I was able to identify the issue pretty fast, it was the order of variables. With that out of the way I thought I'm in the clear, only to realize that math just refuses to work.

<<set $looks = Math.abs(0 + $fitness + $looksmodwear + $looksmodmakeup) >> does nothing, $looks stays at 0 when I spam fitness training
<<set $looks = 0 + $fitness + $looksmodwear + $looksmodmakeup >> does nothing, again
<<set $maxenergy = 10 + $fitness / 10>> also does nothing

What am I missing? Motoslave docs state that simple expressions should be working. Is it StoryInit passage? Do I need to cook up a roundabout way to update stats?
 

guest1492

Member
Apr 28, 2018
312
262
I don't see anything wrong with the examples you shared. They work fine for me after I initialize all the variables with values. The problem must be coming from somewhere else.
 

Alcahest

Engaged Member
Donor
Game Developer
Jul 28, 2017
3,131
4,032
Check that $looks actually changes by typing out the value before and after the change in the place where you increase $fitness. You will probably find that it does change.

I think this is an update issue. If you have the value of $looks displayed somewhere, like in the sidebar, just changing the value of the variable will not update it on screen. You must update that part of the page, for instance using <<replace>>
 
Last edited:
  • Like
Reactions: osanaiko