Hey guys. I’m trying to create an RPG based battle menu with choicescript but I’m having a hell of a time.
I found a way to make the battle menu by creating a variable for each stat and for each change in the stat. So for example I have three random stats: Strength 1, Speed 1, Jump 1. I made a variable for each stat, but I also have to make variable for every increase or decrease in each stat. So like this:
*Label attack
*Choice
# Bite him
*If (strength > 0) and (strength < 2)
*set enemy_hp -0
*goto defend
*elseif (strength > 1) and (strength < 3)
*set enemy_hp -2
*goto defend
(This repeats until I reach the stat cap. Which is all the way to a hundred in my game.)
This is what I usually do get the stats to match up with a battle. Depending on how strong the MC’s stat is the damage will be higher or lower. So I now have to code each and every number that stat could reach until the stat cap/limit. So if the stat cap is at 100 then I would have to repeat the if statements a hundred times. Then I’d have to do the same for the other stats like Speed and Jump. It’s literally a pain in the ass and very time consuming.
What I’ve come here to ask is, can there be a way that I can make a battle menu that is flexible enough to change along with the MC’s stats without doing all of this work?
Also, is it possible to have some variables in another scene that I can call on with a command at any point then have it return back to it’s place? Like a battle happen in chapter 1 and I press attack. I run a goto_scene to another scene where the code is and the code automatically goes back to chapter 1 after I press attack. If this could work I wouldn’t have to bog down the main scenes with a hundred lines of code.
Thanks lots for responding. I really appreciate the link. So it seems gosub can fix jumping between scenes if I understand that right. I’m still kinda new to choicescript so I didn’t know all of this.
Oh, about the first solution. What does the code after else do? Does it subtract the enemy health from the MC-s strength?
Ahhh! A light bulb just came on in my head! Thanks for the explanation. This is so much easier! Can you imagine what I had to go though sitting down to right almost threw hundred lines of code?
If you ever decide to change how much damage is done. Like, say maybe damage is half the strength. Or maybe, the damage equals strength up to 50, but then is 50 + 1/2 of everything over 50.
You can still do that easily without having to write tons of code.
*temp strength_damage 1
*comment I always give my numeric variables a value other than zero.
*label calculate_damage
*if strength < 2
*set strength_damage 0
*goto calc_enemy_hp
*comment the below sets the damage to equal the value of strength
*elseif (strength >= 2) and (strength <= 50)
*set strength_damage strength
*goto calc_enemy_hp
*comment the below sets the strength damage to 50 + half the value over 50.
*else
*set strength_damage (50 + (round((strength - 50)/2)))
*goto calc_enemy_hp
*label calc_enemy_hp
*set enemy_hp -strength_damage
Sometimes it helps to create that extra variable to hold the temporary value.
So, for example, if strength is 55, strength_damage would be set to 53.
50 + round((55-50)/2))
55-50 is 5. 5/2 is 2.5. round(2.5) is 3. 50 + 3 = 53.
ETA: If you want to round down instead of using standard rounding rules, you’ll have to use modulo.
*temp var 55
*temp ans 1
*comment this answer will be 27.5
*set ans var / 2
${ans}
*comment the answer will be 28
Standard rounding:
*set ans round(var/2)
${ans}
*comment this answer will be 27
Rounddown:
*temp var2
*set var2 (var/2) modulo 1
*set ans (var/2) - var2
${ans}
(You could do that without creating the var2, but I think it is a bit neater with it).
Wow. I didn’t know we could do all of this with choicescript. This is insanely useful. If I had known this method Hunter Sky would have been finished months ago😢. What a shame.
So I could use this method in calculating damage against the MC too right? The enemy has their own specific stats. So I could just use this reversed.
Choicescript may not be a full programming language, but it does more than people realize, I think.
And, yes, you can use the same process. Just make sure to change all the variables to be the ones representing enemy strength, mc hp, etc.
It helps to create a space for yourself to test things out. Personally, I use the start of chapter one for my playground. I test things there, run the game, see if it does what I think, tweak and try again. That is easier than having to play through to where I’m trying something new.
You also could change enemy_hp and mc_hp using the exactly the same code by doing this…
-In startup-
*create target ""
Then whenever you need to decide who is taking damage you just set target to that person.
*choice
#You attack your opponent.
*set target "enemy"
*goto damage_count
#They attack you.
*set target "mc"
*goto damage_count
*label damage_count
*temp victim target&"_hp"
*temp damage target&"_strength"
*set {victim} - {damage}
This bit of code will change mutiple variables depending on who you set as target. So it would also work if you wanted multiple combatants