# Coding a battle system, help with math operations

I’m currently trying to code a battle system, and I ran into trouble if some things even work:

Summary
``````*temp controll 0
*temp en_controll 0
*temp enemy_success ""
*temp success ""
*temp hurt 0
*temp enemy_hurt 0
*rand en_controll 1-100
*rand controll 1-100

*label test_stats
*set str 9
*set def 10
*set supp 6
*set fort 100
*set con 75
*goto enemies

*label enemies
*if (enemy = "enemy1")
*set enemy_str 10
*set enemy_def 7
*set enemy_supp 7
*set enemy_fort 100
*set enemy_con 95
*goto enemy_cont_cal
etc

*label enemy_cont_cal
*if ((en_controll <= enemy_con) and (controll =1))
*set enemy_success "crit"
*goto cont_cal
*elseif ((en_controll <= enemy_con) and (controll !=1))
*set enemy_success "hit"
*goto cont_cal
*elseif ((en_controll > enemy_con) and (controll !=100))
*set enemy_success "miss"
*goto cont_cal
*else
*set enemy_success "fail"
*goto cont_cal

*label cont_cal
*if ((controll <= con) and (controll =1))
*set old_success "crit"
*goto battle_kind
*elseif ((controll <= con) and (controll !=1))
*set old_success "hit"
*goto battle_kind
*elseif ((controll > con) and (controll !=100))
*set old_success "miss"
*goto battle_kind
*else
*set old_success "fail"
*goto battle_kind

*label battle_kind
*if ((attack) and (enemy_attack))
*if (success = "crit")
*if (enemy_success = "fail")
*set enemy_hurt round(str * 4)
*set hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt round(str * 2)
*set hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt round(str)
*set hurt 0
*goto damage_cal
*elseif
*set enemy_hurt round(str / 2)
*set hurt round(enemy_str / 2)
*goto damage_cal
*else (success = "hit")
*if (enemy_success = "fail")
*set enemy_hurt round(str * 2)
*set hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt round(str)
*set hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt 0
*set hurt 0
*goto damage_cal
*elseif
*set enemy_hurt round(str)
*set hurt round(enemy_str / 2)
*goto damage_cal
*else (success = "miss")
*if (enemy_success = "fail")
*set enemy_hurt round(str / 2)
*set hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt 0
*set hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt 0
*set hurt round(enemy_str)
*goto damage_cal
*elseif
*set enemy_hurt 0
*set old_hurt round(enemy_str * 2)
*goto damage_cal
*else (success = "fail")
*if (enemy_success = "fail")
*set enemy_hurt round(enemy_str * 2)
*set hurt round(old_str * 2)
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt 0
*set hurt round(str)
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt 0
*set hurt round(enemy_str + str)
*goto damage_cal
*elseif
*set enemy_hurt 0
*set hurt round(enemy_str * 4)
*goto damage_cal

*label damage_cal
*if (attack)
*set fort %-(hurt)
*set enemy_fort %-(enemy_hurt)
*goto game_over_check
etc
``````

What I’m trying is thus:
The game meant to roll whether or not an action succeeds, and then subtract a percentage from the fortitude stat (basically lifepoints) based on the damage taken (based on the strength/defense stat and the success)
I’m not certain certain operations would even work like i have it there (like the %-(var))

Hopefully you can help.

2 Likes

Tried to do var1 %-(var2), seems to work.

This gives “Invalid expression” error message.
\${var} is for displaying variables, not for comparing them.
Try *if ((en_controll) <= (enemy_con)) ect. instead.

Should it be `*set enemy_hurt 0`?

Where is label battle_cal?

shoot
Okay, battle_cal should be enemy_cont_cal in this
with the \${}'s i wasn’t certain if that was how it checks that at the time of typing.

edit: adjusted. Hope I didn’t miss any paranthesis…

Where are en_controll and controll variables set?

Ah bother, forgot those… let me fix it. (and add something for testing purpose)

There

I see where enemy_success and old_success varriables come from, but what is “success” from the label battle_kind? And where did old_success go in that label? Were they supposed to be the same variable?

yes they are… sorry again

Under the label battle_kind, where did “attack” and “enemy_attack” variables come from?

`*else (success = "fail")`
You don’t need to put anything after *else command.

You haven’t replaced old_success wiht success under label cont_cal.

Ah, the attack var would be set in the main game upon making a choice.

Ill add things in once im back on desktop. Thank you agaib

Either replace *elseif with *else, or add a condition after *elseif.

label battle_kind determines how much the main character and their enemy are hurt. There are a lot of repeating lines there, like `*set enemy_hurt 0`.
Wouldn’t it be easier to set `hurt` under `enemy_cont_cal` and `enemy_hurt` under `cont_cal`?
Like this:

``````*label enemy_cont_cal
*if ((en_controll <= enemy_con) and (controll =1))
*set hurt (round(enemy_str * 4))
*goto cont_cal
``````

The hurt/enemy_hurt are based on if an attack succeeds or not.
There will be routines for defending too, and I think there that order should work, but right now it’s just for both attacking.

What are `old_hurt` and `old_str` under label battle_kind? Looks like you renamed variables and missed some.

Then we’ll check that part it when defending will be done.

Thank you. I’ll see to it.

There is one more problem. There is no text for player to see (and for potential tester to understand what is going on in each label).
Like this:

``````*label enemy_cont_cal
\${enemy} launches an attack!
*if ((en_controll <= enemy_con) and (controll =1))
Your enemy manages to land a critical hit!
*set enemy_success "crit"
*goto cont_cal
*elseif ((en_controll > enemy_con) and (controll !=100))
Luckily, your enemy misses you entirely.
*set enemy_success "miss"
*goto cont_cal
*else
Enemy can't control their power and hurts themselves instead.
*set enemy_success "fail"
*goto cont_cal
``````

Its meant to be invisible. The text comes in the scenes itself (ill add this later, sorry)

Once more, I hope this makes more sense:

Summary
``````*temp controll 0
*temp en_controll 0
*temp enemy_success ""
*temp old_success ""
*temp old_hurt 0
*temp enemy_hurt 0
*temp old_inter false
*temp en_inter false
*rand en_controll 1-100
*rand controll 1-100

*label enemies_old
*if (enemy_old = "enemy1")
*set enemy_str 10
*set enemy_def 7
*set enemy_supp 7
*set enemy_fort 100
*set enemy_con 95
*goto battle_cal

*label enemy_cont_cal
*if ((en_controll <= enemy_con) and (controll =1))
*set enemy_success "crit"
*goto cont_cal
*elseif ((en_controll <= enemy_con) and (controll !=1))
*set enemy_success "hit"
*goto cont_cal
*elseif ((en_controll > enemy_con) and (controll !=100))
*set enemy_success "miss"
*goto cont_cal
*else
*set enemy_success "fail"
*goto cont_cal

*label cont_cal
*if ((controll <= old_con) and (controll =1))
*set old_success "crit"
*goto battle_kind
*elseif ((controll <= old_con) and (controll !=1))
*set old_success "hit"
*goto battle_kind
*elseif ((controll > old_con) and (controll !=100))
*set old_success "miss"
*goto battle_kind
*else
*set old_success "fail"
*goto battle_kind

*comment put outcome flavortext here bits here

*label battle_kind
*if ((old_attack) and (enemy_attack))
*if (old_success = "crit")
*if (enemy_success = "fail")
*set enemy_hurt round(old_str * 4)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt round(old_str * 2)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt round(old_str)
*set old_hurt 0
*goto damage_cal
*else
*set enemy_hurt round(old_str / 2)
*set old_hurt round(enemy_str / 2)
*goto damage_cal
*elseif (old_success = "hit")
*if (enemy_success = "fail")
*set enemy_hurt round(old_str * 2)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt round(old_str)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*else
*set enemy_hurt round(old_str)
*set old_hurt round(enemy_str / 2)
*goto damage_cal
*elseif (old_success = "miss")
*if (enemy_success = "fail")
*set enemy_hurt round(old_str / 2)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt 0
*set old_hurt round(enemy_str)
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt round(enemy_str * 2)
*goto damage_cal
*else
*if (enemy_success = "fail")
*set enemy_hurt round(enemy_str * 2)
*set old_hurt round(old_str * 2)
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt 0
*set old_hurt round(old_str)
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt 0
*set old_hurt round(enemy_str + old_str)
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt round(enemy_str * 4)
*goto damage_cal
*elseif ((old_attack) and (enemy_defend))
*if (old_success = "crit")
*if (enemy_success = "fail")
*set enemy_hurt round((old_str + enemy_def) * 2)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt round(old_str * 2)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set enemy_hurt round(old_str / 2)
*set old_hurt 0
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*elseif (old_success = "hit")
*if (enemy_success = "fail")
*set enemy_hurt round(old_str * 2)
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt round(old_str)
*set old_hurt 0
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*elseif (old_success = "miss")
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt round(old_str * 2)
*goto damage_cal
*elseif ((old_defend) and (enemy_attack))
*if (enemy_success = "crit")
*if (old_success = "fail")
*set old_hurt round((old_def + enemy_str) * 2)
*set enemy_hurt 0
*goto damage_cal
*elseif (old_success = "miss")
*set old_hurt round(enemy_str * 2)
*set enemy_hurt 0
*goto damage_cal
*elseif (old_success = "hit")
*set old_hurt round(enemy_str / 2)
*set enemy_hurt 0
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*if (old_success = "fail")
*set old_hurt round(enemy_str * 2)
*set enemy_hurt 0
*goto damage_cal
*elseif (old_success = "miss")
*set old_hurt round(enemy_str)
*set enemy_hurt 0
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*else
*set old_hurt 0
*set enemy_hurt round(enemy_str * 2)
*goto damage_cal
*elseif ((old_defend) and (enemy_defend))
*set old_hurt 0
*set enemy_hurt 0
*goto damage_cal1
*elseif ((old_support) and (enemy_defend))
*set old_hurt 0
*set enemy_hurt 0
*goto support_cal1
*elseif ((old_support) and (enemy_support))
*set old_hurt 0
*set enemy_hurt 0
*goto support_cal1
*elseif ((old_defend) and (enemy_support))
*set old_hurt 0
*set enemy_hurt 0
*goto support_cal1
*elseif ((old_support) and (enemy_attack))
*if (enemy_success = "crit")
*set old_hurt round(enemy_str * 4)
*set old_inter true
*set enemy_hurt 0
*goto damage_cal
*elseif (enemy_success = "hit")
*set old_hurt round(enemy_str * 2)
*set old_inter true
*set enemy_hurt 0
*goto damage_cal
*elseif (enemy_success = "miss")
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*else
*set old_hurt 0
*set enemy_hurt round(enemy_str * 2)
*goto damage_cal
*else
*if (old_success = "crit")
*set enemy_hurt round(old_str * 4)
*set en_inter true
*set old_hurt 0
*goto damage_cal
*elseif (old_success = "hit")
*set enemy_hurt round(old_str * 2)
*set en_inter true
*set old_hurt 0
*goto damage_cal
*elseif (old_success = "miss")
*set enemy_hurt 0
*set old_hurt 0
*goto damage_cal
*else
*set enemy_hurt 0
*set old_hurt round(old_str * 2)
*goto damage_cal

*label damage_cal
*set old_fort %-(old_hurt)
*set enemy_fort %-(enemy_hurt)
*if en_inter
*goto check1
*elseif old_inter
*goto check2
*else
*goto check
``````

the check labels would then contain the *sets for the outcome and the return, which would then go to the respective final outcome texts for the round.
(and I need to code in the flavor text)

if I go to a label below the *temps it won’t reset them upon entering the sub_scene again, right?

Probably not, if you don’t exit the scene file.