Scripting issue

So, I'm working on a script that is defining a local variable based on $game_variables[15]. I'm an incredibly novice scripter, so I don't understand what the issue going on here is.

Variable 15 will be set to something (say, 192), but it will be treated as if it were the first item in a || list. Checking the variable externally says that it is 192, but the script is treating it as 144 (the first number that appears). Can anyone let me know what I'm doing wrong?

Affected sections:

Spoiler
class Game_Interpreter def apply_gear optimalWeapon = 0 if $game_variables[15] == 144||145||146 optimalWeapon = 62 elsif $game_variables[15] == 147||148||149 optimalWeapon = 63 elsif $game_variables[15] == 150||151||152 optimalWeapon = 64 elsif $game_variables[15] == 153||154||155 optimalWeapon = 65 elsif $game_variables[15] == 156||157||158 optimalWeapon = 66 elsif $game_variables[15] == 159||160||161 optimalWeapon = 67 elsif $game_variables[15] == 162||163||164 optimalWeapon = 68 elsif $game_variables[15] == 165||166||167 optimalWeapon = 69 elsif $game_variables[15] == 168||169||170 optimalWeapon = 70 elsif $game_variables[15] == 171||172||173 optimalWeapon = 71 elsif $game_variables[15] == 174||175||176 optimalWeapon = 72 elsif $game_variables[15] == 177||178||179 optimalWeapon = 73 elsif $game_variables[15] == 180||181||182 optimalWeapon = 74 elsif $game_variables[15] == 183||184||185 optimalWeapon = 75 elsif $game_variables[15] == 186||187||188 optimalWeapon = 76 elsif $game_variables[15] == 189||190||191 optimalWeapon = 77 elsif $game_variables[15] == 192||193||194 optimalWeapon = 78 elsif $game_variables[15] == 195||196||197 optimalWeapon = 79 elsif $game_variables[15] == 198||199||200 optimalWeapon = 80 elsif $game_variables[15] == 201||202||203 optimalWeapon = 81 elsif $game_variables[15] == 204||205||206 optimalWeapon = 82 elsif $game_variables[15] == 207||208||209 optimalWeapon = 83 elsif $game_variables[15] == 210||211||212 optimalWeapon = 84 elsif $game_variables[15] == 213||214||215 optimalWeapon = 85 elsif $game_variables[15] == 216||217||218 optimalWeapon = 86 elsif $game_variables[15] == 219||220||221 optimalWeapon = 87 elsif $game_variables[15] == 222||223||224 optimalWeapon = 88 elsif $game_variables[15] == 225||226||227 optimalWeapon = 89 elsif $game_variables[15] == 228||229||230 optimalWeapon = 90 elsif $game_variables[15] == 231||232||233 optimalWeapon = 91 elsif $game_variables[15] == 234||235||236 optimalWeapon = 92 elsif $game_variables[15] == 237||238||239 optimalWeapon = 93 elsif $game_variables[15] == 240||241||242 optimalWeapon = 94 elsif $game_variables[15] == 243||244||245 optimalWeapon = 95 elsif $game_variables[15] == 246||247||248 optimalWeapon = 96 elsif $game_variables[15] == 249||250||251 optimalWeapon = 97 end
Spoiler
Code:
if $game_actors[$game_variables[13]].equips[0].template_id == $game_variables[16]#optimalWeapon      optimalTrue = true      plusApply = optimalWeapon + 145    else      optimalTrue = false      slashApply = optimalWeapon + 191    end        if optimalTrue == true      if $game_variables[15] == 144||147||150||153||156||159||162||165||168||171||                      174||177||180||183||186||189||192||195||198||201||                      204||207||210||213||216||219||222||225||228||231||                      234||237||240||243||246||249        if $game_actors[$game_variables[13]].equips[0].plus_id==0          set_plus($data_weapons[$game_actors[$game_variables[13]].equips[0].id], plusApply)          $game_party.lose_item($data_armors[gearUsed], 1)          $game_message.background = 0          $game_message.position = 2          $game_message.add("The weapon was upgraded!")        else          $game_message.background = 0          $game_message.position = 2          $game_message.add("The weapon is already at this level!")        end
Thanks in advance for any help that can be offered! I can post my full script if helpful, but I found only these sections to be pertinent.

~Tya
I've moved this thread to Script support. Please be sure to post your threads in the correct forum next time. Thank you.
|| or doesn't mean the same thing in programming that it does when talking. You can't say "if a is equal to b or c". You have to say "if a is equal to be or a is equal to c".


Try this:

if [144,145,146].include?($game_variables[15])
However, your script is very long-winded. If you're going to have all the values incrementally in groups of 3, you're better off using a div (/) operator. However, I'm too brain-dead at the moment to actually figure out the exact commands, so hopefully someone else will be able to shorten it for you.
Also, you could instead use a switch on that variable and do this:

Code:
case $game_variables[15]   when 144, 145, 146      # do something   when 147..149      # do something else   else      # some default actionend
Note that you can group number blocks together, so instead of writing 144, 145, 146 you can say 144..146.
also why do you input this in game_interpreter? I know it's for script call we mostly implement here but this not the best place for situate that haha 
Scripts are usually placed in Game_Interpreter, so you can easily call them from events. Since script commands in events are executed inside the interpreter, you can simply name the method without refering to a module/global variable.


However, i wouldn't put the whole method there but move it to a module and have the Game_Interpreter simply contain a shortcut, if needed.
Sorry for posting in the wrong forum, I'm not familiar with these forums yet and didn't see scripting support.

Thank you guys so much for the help, it's all greatly appreciated. I figured that my || checks were a problem (I've mostly coded in C# and couldn't for the life of me remember or find how Ruby did it), and I went with Iavra's suggestion. Works absolutely flawlessly now.

The script is really long-winded, but I couldn't figure out a formula to match up the values the way I have them, and I'm happy enough to manually implement everything, since I'm making this purely for my own use. I'll clean it up and make it more accessible if it seems like other people could get use out of it, since it's an addon to Tsukihime's affix script.

I figured Game_Interpreter was probably not the best place, but I have absolutely no experience with Ruby-from-scratch and I wasn't sure the best way to go about it. All I knew was that that was where my call needed to be.

On that note, if anyone wants to help me clean it up or format it better, here is the entire script:

Spoiler
module RPG class RPG::Skill < RPG::UsableItem def gear_first return @gear_first unless @gear_first.nil? # parse the note to get any results res = self.note.match(/<gear: (\d+)>/i) if res # assign it a value if found @gear_first = res[1].to_i else # give it a fallback value @gear_first = -1 end return @gear_first end endendclass Game_Interpreter def gear_used gear_first endendclass Game_Interpreter def apply_gear #================================================================================# Figures out the optimal weapon depending on which item/skill is applying the# upgrade.#================================================================================ optimalWeapon = 0 case $game_variables[15] when 144, 145, 146 optimalWeapon = 62 when 147, 148, 149 optimalWeapon = 63 when 150, 151, 152 optimalWeapon = 64 when 153, 154, 155 optimalWeapon = 65 when 156, 157, 158 optimalWeapon = 66 when 159, 160, 161 optimalWeapon = 67 when 162, 163, 164 optimalWeapon = 68 when 165, 166, 167 optimalWeapon = 69 when 168, 169, 170 optimalWeapon = 70 when 171, 172, 173 optimalWeapon = 71 when 174, 175, 176 optimalWeapon = 72 when 177, 178, 179 optimalWeapon = 73 when 180, 181, 182 optimalWeapon = 74 when 183, 184, 185 optimalWeapon = 75 when 186, 187, 188 optimalWeapon = 76 when 189, 190, 191 optimalWeapon = 77 when 192, 193, 194 optimalWeapon = 78 when 195, 196, 197 optimalWeapon = 79 when 198, 199, 200 optimalWeapon = 80 when 201, 202, 203 optimalWeapon = 81 when 204, 205, 206 optimalWeapon = 82 when 207, 208, 209 optimalWeapon = 83 when 210, 211, 212 optimalWeapon = 84 when 213, 214, 215 optimalWeapon = 85 when 216, 217, 218 optimalWeapon = 86 when 219, 220, 221 optimalWeapon = 87 when 222, 223, 224 optimalWeapon = 88 when 225, 226, 227 optimalWeapon = 89 when 228, 229, 230 optimalWeapon = 90 when 231, 232, 233 optimalWeapon = 91 when 234, 235, 236 optimalWeapon = 92 when 237, 238, 239 optimalWeapon = 93 when 240, 241, 242 optimalWeapon = 94 when 243, 244, 245 optimalWeapon = 95 when 246, 247, 248 optimalWeapon = 96 when 249, 250, 251 optimalWeapon = 97 else optimalWeapon = 0 end #================================================================================# Figures out which armor to remove.#================================================================================ gearUsed = $data_skills[$game_variables[15]].gear_first #================================================================================# Used for catching errors while testing.#================================================================================ $game_variables[16] = optimalWeapon $game_variables[17] = $game_actors[$game_variables[13]].equips[0].template_id#================================================================================# Checks if the actor has the optimal weapon.#================================================================================ if $game_actors[$game_variables[13]].equips[0].template_id == $game_variables[16]#optimalWeapon optimalTrue = true plusApply = optimalWeapon + 145 else optimalTrue = false slashApply = optimalWeapon + 191 end #================================================================================# Applies plusses or slashes to the weapon as specified.#================================================================================ if optimalTrue == true case when 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 189, 192, 195, 198, 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231, 234, 237, 240, 243, 246, 249 if $game_actors[$game_variables[13]].equips[0].plus_id==0 set_plus($data_weapons[$game_actors[$game_variables[13]].equips[0].id], plusApply) $game_party.lose_item($data_armors[gearUsed], 1) $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon was upgraded!") else $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is already at this level!") end when 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 205, 208, 211, 214, 217, 220, 223, 226, 229, 232, 235, 238, 241, 244, 247, 250 if $game_actors[$game_variables[13]].equips[0].plus_id==0 $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is not level + yet!") else if $game_actors[$game_variables[13]].equips[0].plusplus_id==0 set_plusplus($data_weapons[$game_actors[$game_variables[13]].equips[0].id], plusApply) $game_party.lose_item($data_armors[gearUsed], 1) $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon was upgraded!") else $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is already at this level!") end end when 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 176, 179, 182, 185, 188, 191, 194, 197, 200, 203, 206, 209, 212, 215, 218, 221, 224, 227, 230, 233, 236, 239, 242, 245, 248, 251 if $game_actors[$game_variables[13]].equips[0].plus_id==0 $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is not level + yet!") else if $game_actors[$game_variables[13]].equips[0].plusplus_id==0 $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is not level ++ yet!") else if $game_actors[$game_variables[13]].equips[0].plusplusplus_id==0 set_plusplusplus($data_weapons[$game_actors[$game_variables[13]].equips[0].id], plusApply) $game_party.lose_item($data_armors[gearUsed], 1) $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon was upgraded!") else $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is already at this level!") end end end end elsif optimalTrue == false case $game_variables[15] when 144, 147, 150, 153, 156, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 189, 192, 195, 198, 201, 204, 207, 210, 213, 216, 219, 222, 225, 228, 231, 234, 237, 240, 243, 246, 249 if $game_actors[$game_variables[13]].equips[0].slash_id==0 set_slash($data_weapons[$game_actors[$game_variables[13]].equips[0].id], slashApply) $game_party.lose_item($data_armors[gearUsed], 1) $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon was upgraded!") else $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is already at this level!") end when 145, 148, 151, 154, 157, 160, 163, 166, 169, 172, 175, 178, 181, 184, 187, 190, 193, 196, 199, 202, 205, 208, 211, 214, 217, 220, 223, 226, 229, 232, 235, 238, 241, 244, 247, 250 if $game_actors[$game_variables[13]].equips[0].slash_id==0 $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is not level / yet!") else if $game_actors[$game_variables[13]].equips[0].slashslash_id==0 set_slashslash($data_weapons[$game_actors[$game_variables[13]].equips[0].id], slashApply) $game_party.lose_item($data_armors[gearUsed], 1) $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon was upgraded!") else $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is already at this level!") end end when 146, 149, 152, 155, 158, 161, 164, 167, 170, 173, 176, 179, 182, 185, 188, 191, 194, 197, 200, 203, 206, 209, 212, 215, 218, 221, 224, 227, 230, 233, 236, 239, 242, 245, 248, 251 if $game_actors[$game_variables[13]].equips[0].slash_id==0 $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is not level / yet!") else if $game_actors[$game_variables[13]].equips[0].slashslash_id==0 $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is not level // yet!") else if $game_actors[$game_variables[13]].equips[0].slashslashslash_id==0 set_slashslashslash($data_weapons[$game_actors[$game_variables[13]].equips[0].id], slashApply) $game_party.lose_item($data_armors[gearUsed], 1) $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon was upgraded!") else $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is already at this level!") end end end end end optimalWeapon = 0 plusApply = 0 slashApply = 0 end end
I also need a good way to make sure that the actor has a weapon equipped, and return some message to signify that they have no weapon if they do not. Everything I keep trying doesn't work and still runs into errors due to having no weapon.

In any case, you guys are already great, and I'll keep toying with it myself if no one has any suggestions.

Thanks a lot!

~Tya
try

optimalWeapon = 14 + $game_variables[15]/3

(either use integer or trunc to make it whole numbers)
 

You just have to implement the else for numbers lower or higher than your list

Edit:

and for your other lists, use the modulo operator:

case $game_variables[15] % 3

 when 0  (everything 144, 147 following)

when 1 (everything 145, 148 following)

when 2 (everything 146, 149 following)
Thanks a lot, Andar, that works perfectly and is much simpler.

Still looking for suggestions on where to put/how to organize things if not in Game_Interpreter.
Well, you're talking about an optimal weapon for an actor, so I'd put it in Game_Actor, and add a method to Game_Interpreter to call it, which simply does the $game_actors[id].new_method call, passing the arguments that you send in to the script.
It's actually the optimal weapon for the upgrade (ex. Fire upgrades are optimal on the Fire Sword). Would that still be the best route to go?
I see a lot of references to $game_actor in there.


Since weapons are static objects (created in the database) unless you have a script that lets you customize weapons, I'd still put it into Game_Actor. If you're customizing weapons, RPG::Weapon might be the better place. You can use the help file (F1 in the editor) to see how that's defined.
I honestly cannot figure out how to make that work. I'm thinking I'll just have to leave it be for the time being, unless I can get a more direct explanation of what to do. Sorry I'm so clueless about this stuff, but I mean it when I say I have no idea what I'm doing.

Current version:

Spoiler
module TYA module TYA_USE_GEAR FIRST_GEAR_SKILL = 144 LAST_GEAR_SKILL = 251 end #TYA_USE_GEARend # TYAmodule RPG class RPG::Skill < RPG::UsableItem def gear_first return @gear_first unless @gear_first.nil? # parse the note to get any results res = self.note.match(/<gear: (\d+)>/i) if res # assign it a value if found @gear_first = res[1].to_i else # give it a fallback value @gear_first = -1 end return @gear_first end endendclass Game_Interpreter def gear_used gear_first endend class Game_Interpreter def fail_same $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is already at this level!") end def fail_low $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon is not high enough level yet!") end def gear_success $game_message.background = 0 $game_message.position = 2 $game_message.add("The weapon was upgraded!") end def apply_gear #================================================================================# Figures out the optimal weapon depending on which item/skill is applying the# upgrade.#================================================================================ optimalWeapon = 0 case $game_variables[15] when TYA::TYA_USE_GEAR::FIRST_GEAR_SKILL..TYA::TYA_USE_GEAR::LAST_GEAR_SKILL optimalWeapon = 14 + $game_variables[15]/3 else optimalWeapon = 0 end #================================================================================# Figures out which armor to remove.#================================================================================ gearUsed = $data_skills[$game_variables[15]].gear_first #================================================================================# Used for catching errors while testing.#================================================================================ $game_variables[16] = optimalWeapon $game_variables[17] = $game_actors[$game_variables[13]].equips[0].template_id#================================================================================# Checks if the actor has the optimal weapon.#================================================================================ if $game_actors[$game_variables[13]].equips[0].template_id == $game_variables[16]#optimalWeapon optimalTrue = true plusApply = optimalWeapon + 145 else optimalTrue = false slashApply = optimalWeapon + 191 end #================================================================================# Applies plusses or slashes to the weapon as specified.#================================================================================ if optimalTrue == true case $game_variables[15] % 3 when 0 if $game_actors[$game_variables[13]].equips[0].plus_id==0 set_plus($data_weapons[$game_actors[$game_variables[13]].equips[0].id], plusApply) $game_party.lose_item($data_armors[gearUsed], 1) gear_success else fail_same end when 1 if $game_actors[$game_variables[13]].equips[0].plus_id==0 fail_low else if $game_actors[$game_variables[13]].equips[0].plusplus_id==0 set_plusplus($data_weapons[$game_actors[$game_variables[13]].equips[0].id], plusApply) $game_party.lose_item($data_armors[gearUsed], 1) gear_success else fail_same end end when 2 if $game_actors[$game_variables[13]].equips[0].plus_id==0 fail_low else if $game_actors[$game_variables[13]].equips[0].plusplus_id==0 fail_low else if $game_actors[$game_variables[13]].equips[0].plusplusplus_id==0 set_plusplusplus($data_weapons[$game_actors[$game_variables[13]].equips[0].id], plusApply) $game_party.lose_item($data_armors[gearUsed], 1) gear_success else fail_same end end end end elsif optimalTrue == false case $game_variables[15] % 3 when 0 if $game_actors[$game_variables[13]].equips[0].slash_id==0 set_slash($data_weapons[$game_actors[$game_variables[13]].equips[0].id], slashApply) $game_party.lose_item($data_armors[gearUsed], 1) gear_success else fail_same end when 1 if $game_actors[$game_variables[13]].equips[0].slash_id==0 fail_low else if $game_actors[$game_variables[13]].equips[0].slashslash_id==0 set_slashslash($data_weapons[$game_actors[$game_variables[13]].equips[0].id], slashApply) $game_party.lose_item($data_armors[gearUsed], 1) gear_success else fail_same end end when 2 if $game_actors[$game_variables[13]].equips[0].slash_id==0 fail_low else if $game_actors[$game_variables[13]].equips[0].slashslash_id==0 fail_low else if $game_actors[$game_variables[13]].equips[0].slashslashslash_id==0 set_slashslashslash($data_weapons[$game_actors[$game_variables[13]].equips[0].id], slashApply) $game_party.lose_item($data_armors[gearUsed], 1) gear_success else fail_same end end end end end optimalWeapon = 0 plusApply = 0 slashApply = 0 end end
Everything works as-is, so I'm not desparate to change things except to follow conventions.

Original thread: https://forums.rpgmakerweb.com/threads/scripting-issue.40417/