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.

upcase?

Kaito

Member

Hiya...Well...I found this method in a script I'm editing...:
Code:
      }
      if count > 0
        hit = steal_prob * 200
        items.size.times { |i|
          hit = [hit / 2, 1].max
          next if self.stolen_items_flag[i]
          item = items[i]
          hit_result = (rand(100) < hit)
          if hit_result
            [COLOR=Red][b]case item[0].upcase[/b][/COLOR]
            when "B"
              self.stolen_items_flag[i] = true
              next
            when "I" 
              steal_item = $data_items[item[1]].name
              $game_party.gain_item(item[1], 1)
            when "W"
              steal_item = $data_weapons[item[1]].name
              $game_party.gain_weapon(item[1], 1)
            when "A"
              steal_item = $data_armors[item[1]].name
              $game_party.gain_armor(item[1], 1)
            when "G"
              steal_item = item[1]
              $game_party.gain_gold(item[1])
            end
            self.stolen_items_flag[i] = true
            break
          end
        }

Well...What is it? The script doesn't have the definition, and I never saw it before... o.O

thank you for any help,
cya~
 
If it´s a String, probably the author wanted to make all of them in upcase, like
Code:
myString = "Hiya!"
myString.upcase
p mystring    => "HIYA!"
This only works for letters ^^
 
It´s in the default Ruby´s code (note RUBY, not RGSS^). It´s a built-in function for String.

Also, try to see the class of this variable by printing it before that line. Like:
Code:
#.......more code above....
if hit_result
# NEW
p item[0].class
case item[0].upcase
#......more code below......
This is just for debugging issues. If it´s not a String class, it´ll surely give nomethod errors.
 
Means that somewhere on your script you´re defining somrthing wrong, or that you may be putting a wrong index for that array. Is it a battle system script?
 

Kaito

Member

It's a steal scipt...Editing it to fit RTAB...Almost got it I think.
Neways...Removing .upcase does make it work...No more error. Do you think it will affect the script if .u[pcase is removed?

thankies~
cya!
 
Maybe, i don´t know how this script IS, from the inside. This is something that you´ll notice with the time, while test playing it.

But at least your problem is solved ^^
 
Just a note:
There are two methods "upcase" and "upcase!". The difference is, the one without ! will create a copy of the string, modify this copy and return it. The one with ! will modify the string itself.

So:
Code:
foo = "foo"
bar = foo.upcase
p bar => "FOO"
p foo => "foo"

foo.upcase!
p foo => "FOO"
There are several different methods in the string-class where this ! is used to differ this behavior.
 

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