Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[Resolved] Small scripting question

SEE MY MOST RECENT POST IN THIS THREAD FOR MY CURRENT QUESTION.

Hey guys, I have a minor question concerning a conditional branch.

http://i229.photobucket.com/albums/ee6/ ... estion.png[/img]

My goal is to have it so that while weapon ID 001 is equipped, saving is disabled.

As of now having the weapon equipped or unequipped does not change anything. Help?

(I have it set to Parallel process, and I am using XP.)

Thanks in advance.
 
hmmm... it's still not working...

I tried running it as a script:

Code:
if $game_actors[1].weapon_id == 1
  then @save_disabled = true

but it says that there is a syntax error on line 2.

help?
 
khmp":83587oh5 said:
Xildra":83587oh5 said:
Cool. Oh, and one last thing.

How do I change variables and switches with scripts?

Thanks so much.

It's in the RGSS/RGSS2 FAQ Mr. Xildra.

oh, whoops.  thanks for that.

EDIT: one last question...

DO NOT STEAL THIS SCRIPT
Code:
 if $game_actors[1].weapon_id == 1
  then $game_switches[1] = true
 else $game_switches[1] = false
 end if

 if $game_actors[1].armor1_id == 1
  then $game_switches[4] = true
 else $game_switches[4] = false
 end if

 if $game_actors[1].armor2_id == 5
  then $game_switches[3] = true
 else $game_switches[3] = false
 end if

 if $game_actors[1].armor3_id == 13
  then $game_switches[2] = true
 else $game_switches[2] = false
 end if

 if $game_actors[1].armor4_id == 25
  then $game_switches[5] = true
 else $game_switches[5] = false
 end if

 if $game_actors[1].armor1_id == 2
  then $game_variables[1] = + 1
 else $game_variables[1] = - 1
 end if

 if $game_actors[1].armor2_id == 6
  then $game_variables[2] = + 1
 else $game_variables[2] = - 1
 end if

 if $game_actors[1].armor3_id == 14
  then $game_variables[3] = + 1
 else $game_variables[3] = - 1
 end if

 if $game_actors[1].armor4_id == 26
  then $game_variables[4] = + 1
 else $game_variables[4] = - 1
 end if

 if $game_actors[2].weapon_id == 1
  then $game_switches[1] = true
 else $game_switches[1] = false
 end if

 if $game_actors[2].armor4_id == 26
  then $game_variables[4] = + 1
 else $game_variables[4] = - 1
 end if

it keeps on saying that there is a syntax error on the last line, regardless of what is on that line. i tried adding extra lines, adding "end", but nothing's working. any ideas?
 

khmp

Sponsor

Script stolen MUHAHA :lol:

The problem is that you should be using "+=" and "-=" instead of "= +" and "= -". Might I recommend a different way to handle the switches?
Code:
$game_switches[1] = $game_actors[1].weapon_id == 1

That way it's simplified to one line of code.

Good luck with it Xildra! :thumb:
 
khmp":lfejwewn said:
Script stolen MUHAHA :lol:

The problem is that you should be using "+=" and "-=" instead of "= +" and "= -". Might I recommend a different way to handle the switches?
Code:
$game_switches[1] = $game_actors[1].weapon_id == 1

That way it's simplified to one line of code.

Good luck with it Xildra! :thumb:

hmmm... that could work... what about the ones that effect variables? and would that get rid of the aformentioned problem?

it keeps on saying that there is a syntax error on the last line, regardless of what is on that line. i tried adding extra lines, adding "end", but nothing's working. any ideas?
 
Try this:
Code:
if $game_actors[1].weapon_id == 1
  $game_switches[1] = true
else 
  $game_switches[1] = false
end

if $game_actors[1].armor1_id == 1
  $game_switches[4] = true
else 
  $game_switches[4] = false
end

if $game_actors[1].armor2_id == 5
  $game_switches[3] = true
else 
  $game_switches[3] = false
end

if $game_actors[1].armor3_id == 13
  $game_switches[2] = true
else 
  $game_switches[2] = false
end

if $game_actors[1].armor4_id == 25
  $game_switches[5] = true
else 
  $game_switches[5] = false
end

if $game_actors[1].armor1_id == 2
  $game_variables[1] += 1
else 
  $game_variables[1] -= 1
end

if $game_actors[1].armor2_id == 6
  $game_variables[2] += 1
else 
  $game_variables[2] -= 1
end

if $game_actors[1].armor3_id == 14
  $game_variables[3] += 1
else   
  $game_variables[3] -= 1
end

if $game_actors[1].armor4_id == 26
  $game_variables[4] += 1
else 
  $game_variables[4] -= 1
end

if $game_actors[2].weapon_id == 1
  $game_switches[1] = true
else 
  $game_switches[1] = false
end

if $game_actors[2].armor4_id == 26
  $game_variables[4] += 1
else 
  $game_variables[4] -= 1
end

Besides the above error, it's just end not end if
 
it also looks like you are using "then". I think that is the root of your syntax problem. Fomar cleaned it up so you should have no problems with running the script. getting it to work right the way you want it is another story.

good luck.
 

khmp

Sponsor

Xildra":23l7rolu said:
khmp":23l7rolu said:
Script stolen MUHAHA :lol:

The problem is that you should be using "+=" and "-=" instead of "= +" and "= -". Might I recommend a different way to handle the switches?
Code:
$game_switches[1] = $game_actors[1].weapon_id == 1

That way it's simplified to one line of code.

Good luck with it Xildra! :thumb:

hmmm... that could work... what about the ones that effect variables? and would that get rid of the aformentioned problem?

it keeps on saying that there is a syntax error on the last line, regardless of what is on that line. i tried adding extra lines, adding "end", but nothing's working. any ideas?

Ternary operation would work there:
Code:
$game_variables[4] = $game_actors[2].armor4_id == 26 ? $game_variables[4] + 1 : $game_variables[4] - 1
Or:
Code:
$game_actors[2].armor4_id == 26 ? $game_variables[4] += 1 : $game_variables[4] -= 1
 
okay, so I fixed all of the syntax errors, but now it says:

line 23: ‘Item Abilities’ NoMethodError occurred.

undefined method ‘[]’ for nil:NilClass

the line in question:
Code:
if $game_actors[1].weapon_id == 1 <---------------------------LINE 23
  $game_switches[1] = true
else 
  $game_switches[1] = false
end

the script as of now:

Code:
class Item_Abilities
    
if $game_actors[1].weapon_id == 1 <---------------------------LINE 23
  $game_switches[1] = true
else 
  $game_switches[1] = false
end

if $game_actors[1].armor1_id == 1
  $game_switches[4] = true
else 
  $game_switches[4] = false
end

if $game_actors[1].armor2_id == 5
  $game_switches[3] = true
else 
  $game_switches[3] = false
end

if $game_actors[1].armor3_id == 13
  $game_switches[2] = true
else
  $game_switches[2] = false
end

 if $game_actors[1].armor4_id == 25
  $game_switches[5] = true
else 
  $game_switches[5] = false
end

if $game_actors[1].armor1_id == 2
  $game_variables[1] = + 1
else
  $game_variables[1] = - 1
end

if $game_actors[1].armor2_id == 6
  $game_variables[2] = + 1
else
  $game_variables[2] = - 1
end

if $game_actors[1].armor3_id == 14
  $game_variables[3] = + 1
else 
  $game_variables[3] = - 1
end

if $game_actors[1].armor4_id == 26
  $game_variables[4] = + 1
else
  $game_variables[4] = - 1
end

if $game_actors[2].weapon_id == 1
  $game_switches[1] = true
else
  $game_switches[1] = false
end

if $game_actors[2].armor4_id == 26
  $game_variables[4] = + 1
else
  $game_variables[4] = - 1
end

end

i tried using khmp's one line peices, but the same error cam up on this line:
Code:
$game_switches[1] = $game_actors[1].weapon_id == 1
 

khmp

Sponsor

This code is executing before the array "$game_actors" has been properly initialized is my guess. You need to place this within a method that get's called after $game_actors is created.

Code:
module Item_Abilities
  def self.check
    return if $game_actors.nil? || $game_actors.size == 0
    $game_switches[1] = $game_actors[1].weapon_id == 1
    $game_switches[2] = $game_actors[1].armor1_id == 1
    $game_switches[3] = $game_actors[1].armor2_id == 5
    $game_switches[4] = $game_actors[1].armor3_id == 13
    $game_switches[5] = $game_actors[1].armor4_id == 25
    
    $game_variables[1] = $game_actors[1].armor1_id == 2 ? 
      $game_variables[1] + 1 : $game_variables[1] - 1
    $game_variables[2] = $game_actors[1].armor2_id == 6 ? 
      $game_variables[2] + 1 : $game_variables[2] - 1
    $game_variables[3] = $game_actors[1].armor3_id == 14 ? 
      $game_variables[3] + 1 : $game_variables[3] - 1
    $game_variables[4] = $game_actors[1].armor4_id == 26 ? 
      $game_variables[4] + 1 : $game_variables[4] - 1
  end
end

You also had duplicate testing done on two different conditionals. I included a safety check just in case to prevent crashing. So here's how it'll work. After $game_actors has been initialized. Which is any time after Scene_Title so you can call this code as soon as you get into a map if you want. Using "Script...":
Code:
Item_Abilities.check
That will set all the variables that need to be changed, I think.

Good luck with it Xildra! :thumb:
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top