Converting numerical level to alphabetical

zxdvas

Villager
Member
Joined
Mar 31, 2019
Messages
5
Reaction score
0
First Language
English
Primarily Uses
N/A
I probably only messed up something simple.
I want to convert a numerical level to alphabetical so instead of 1,2,3 , A,B,C is displayed instead
I decided to make an array and just match them
which actually works when I input a fixed number, such as 3 into it
But when I try to call the actor's current level, the error "undefined local variable or method "actor" is shown
which is very weird because in the default, actor.level is used in draw_text
Ruby:
class Window_Base < Window
  Alph = ("A".."Z").to_a
  def grade
      grade=Alph[6-actor.level]
    return grade
    end
  def draw_actor_level(actor, x, y)
    change_color(system_color)
    draw_text(x, y, 32, line_height, "Result")
    change_color(normal_color)
    draw_text(x + 32, y, 24, line_height, grade, 2)
  end
end
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,614
Reaction score
13,208
First Language
English
Primarily Uses
RMMV
So close!

Code:
class Window_Base < Window
  Alph = ("A".."Z").to_a
  def grade(actor)
      grade=Alph[6-actor.level]
    return grade
    end
  def draw_actor_level(actor, x, y)
    change_color(system_color)
    draw_text(x, y, 32, line_height, "Result")
    change_color(normal_color)
    draw_text(x + 32, y, 24, line_height, grade(actor), 2)
  end
end
I haven't tested this, so apologies if there are syntax errors
 

zxdvas

Villager
Member
Joined
Mar 31, 2019
Messages
5
Reaction score
0
First Language
English
Primarily Uses
N/A
Yes. It works. So I actually have to define a fcn that takes on actor and not a new variable.
Thanks a lot.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
39,614
Reaction score
13,208
First Language
English
Primarily Uses
RMMV
The mistake you made is that the actor variable is passed around between functions, and is not a class or a global variable. Your grade function didn't know what actor was. If you take a look, you'll see that actor is passed into draw_actor_level - that's how that function was able to use it. So if you create another function that's called from draw_actor_level and you also want it to use the actor object, you have to pass it in.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

In other news, my new computer is now ordered, and I'll have it in my hot little hands by the end of the week! CAN'T WAIT!!!
I've said my cat's names in such a baby-talk manner over the years, Biggs is now Biggoro, Bella is now Bellllyyaah, and somehow.....somehow Tessa is Sessashan
Did a massive ****up in my code that would have caused the game to crash on most computers and almost released an update without noticing it.
I keep thinking today is Thursday.
And I look forward to the next preview thread coming this afternoon.
And then I realise it's not Thursday at all.
And then I get sad :(

Forum statistics

Threads
100,449
Messages
976,079
Members
132,082
Latest member
nwr
Top