Trouble getting a conditional branch to work with variables.

Status
Not open for further replies.

boikish

Always trying to help :)
Veteran
Joined
Sep 8, 2016
Messages
118
Reaction score
36
First Language
English
Primarily Uses
N/A
Hello everyone,

I am attempting to make something like Blacksmith system in my game, and I'm having some errors.

The way it works is the player chooses a weapon, that weapon ID is then stored in variable 100. I used a plugin to get this to work, and it works without fail every time. The variable always properly stores the weapon ID.

Then, I create a conditional branch, that checks if the Weapon ID is between two numbers, and if so, a switch will be activated and a new event page will load. For the time being, these event pages are simple autoruns with a switch conditions that generate a textbox which says "Level 1/2/3/4 worked."

However, I run into a problem where the switches just don't seem to activate, and I'm unsure why. Possibly something with the script?

Please see below:

upload_2019-5-16_11-31-48.png

This event loads and I'm able to select the weapon, which is then stored in the variable appropriately, but it just stops there.

I had it half working earlier by inverting the order (level 1 on top, level 5 on the bottom), but it would load the wrong Switch almost always.

Any help is appreciated. Thank you kindly. :)
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,527
Reaction score
6,870
First Language
German
Primarily Uses
RMMV
why do you use the script option at all?
It is much easier to check the variable directly, as long as you order the checks correctly.

however, if you really need such a complex code then you should also tell the computer which operation to process first
($gameVariables.value(100) >=20) && ($gameVariables.value(100) <=28)
instead of your variant without paranthesis and in a difficult to read order
 

boikish

Always trying to help :)
Veteran
Joined
Sep 8, 2016
Messages
118
Reaction score
36
First Language
English
Primarily Uses
N/A
@Andar Thanks for the help. I added parentheses and changed the order, and it works, but with a problem.

It appears the earlier script that I referenced as working fine isn't updating the variable until the event processing is closed. So the first time I check something, it won't work. The second time I check something, it will work, but based on the previous selection.

So this brings me to a new question of: Is there a way to select a weapon and store it's ID in a variable? I couldn't find anything other than this plugin online. Which can be found here: https://forums.rpgmakerweb.com/index.php?threads/weapon-and-armor-on-select-item.66540/

And I'd also like to ask about your recommendation of checking the variable directly. Am I missing something here and there's a much easier way to do this.

Thanks a lot.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,527
Reaction score
6,870
First Language
German
Primarily Uses
RMMV
with "directly" I mean not to use script but pure eventing.

Especially for that first script line - I just saw that but why did you use a method of the gamemessage object to set a variable????7
That is probably the reason, game messages are not a direct part and (as with move routes) are sometimes updated out of sync iirc.
Use control variable command, and if you don't have the number to set it directly, use the script line of that command to contain whatever script you have that results in the number.

As for the conditional branch: again, use pure eventing. The first page of the conditional branch contains an option to check a variable.
That is only a single check but again, you usually don't need doublechecks if you use it correctly.
Example to check for numbers between:
Number can be 1 to 100
First check is variable <10 - everything else goes to the else branch.
Second check is variable <20 - you don't have to check for >=10 at the same time because anything smaller than 10 is already blocked by being part of the first check.
Third check is variable <30 - you don't have to check for >=20 at the same time because anything lower is already in the first or second branch.

and so on. And if you want some numbers excluded then it might be best to use the modulo operation of control variable before the conditional branches.

Scripts and plugins have their places - but eventing should always come first unless it would result in too complex commands.
There is a lot you could do with events and in fact some things are much easier to do by eventing instead of scripting.
 

boikish

Always trying to help :)
Veteran
Joined
Sep 8, 2016
Messages
118
Reaction score
36
First Language
English
Primarily Uses
N/A
Regarding the first script line: The script line generates a pop-up window which allows me to select a weapon from my inventory. It then assigns the weapon ID to variable 100. It is simply a function of the plugin I linked above.

Without that plugin, I'm unsure how to:
1.) Create a window that shows all weapons in the inventory
2.) Allows me to select a weapon
3.) Stores the value of that weapon in a variable


Regarding your second point. Yes, I definitely over-complicated things using scripts instead of eventing. I'm surprised I didn't think of this because I've used the same logic before. I think what happened was I had the weapons in a different order, and simply using <X wouldn't work. But since then, I rearranged the weapons so that logic would work, but had it in my head that I had to use scripting. So thanks for the info, much appreciated as always. :)

I'll keep working toward a solution for my first issue, but if you know of anything, please share. Thanks!
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,527
Reaction score
6,870
First Language
German
Primarily Uses
RMMV
OK, didn't realise that.

but that sounds as if the plugin is broken somehow - you should either ask someone for a fix to it or ask for an advanced select item plugin.
I know that there are plugins that modify the select item command to also work for weapon or equipment.
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
6,181
Reaction score
4,300
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Hope y'all are staying healthy, safe and informed. Maybe pick up a new hobby or skill while you're at it.
Wanted to post a video of location i've finished but it doesn't work...
The game jam has done a lot of good in actually kicking my butt into action. I've even gotten over my crippling hatred of mapping thanks to it! :LZSexcite:

(Okay, there's also schoolwork forcing me to get on the computer, but I like to give credit where credit is due.)
Decided to start working on my second biome/area...


I'm sure I'll end up hating and changing things a whole lot over the next week. :LZSexcite:
I feel bad sometimes around others, I hate, and I mean HATE being touched, and I know they don't know I hate it so much

Forum statistics

Threads
95,656
Messages
930,810
Members
125,991
Latest member
harleyquinn
Top