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]Class List

Well, I'm slowly developing an understanding of RGSS, but not quite enough to know what the hell I'm doing here.

This class is supposed to create a window that will print a list of the character classes listed in the classes portion of the dtatbase. I've been trying to work off of some of the other windows, but I can't seem to figure this out:

Code:
 

class Window_Class < Window_Selectable

  def initialize(width, index)

    super(0, 120, 320, 360)

    self.contents = Bitmap.new(width - 32, height - 32)

    @column_max = 1

    self.index = 0

    refresh

  end

  

  def refresh

    self.contents.clear

    @choices = []

    for i in 0..$data_classes.size

      classes = $data_classes[RPG::Class::id]

      if classes != nil

        @choices.push(classes)

      end

    end

    @item_max = @choices.size

    if @item_max > 0

      for i in 0..@item_max

        draw_class(i)

      end

    end

  end

  

  def draw_class(index)

    classes = @choices[index]

    self.contents.draw_text(0, index * 32, 200, 32, classes.name)

  end

end

 

I've tried several different things with line 15, and I can't figure out how to tell it to add the class names to that array and then output them in the draw_class method.

Basically, the output I'm looking for is:

Fighter
Lancer
Warrior
Theif
...


And so forth, unless - of course - I change the class names in the database, then that should reflect the changes...

Can anyone help me with this?

EDIT: Just a note. I'm immitating Window_Skill with the array push thing. It deals with specific actors, so it works differently than this. That's probably why I can't figure it out... I can't find anything in the help contents about $data_classes either.
 
I did try that... but it was complaining then too. I just can't figure out how to get it to list the class names.

Here, I did an edit, and now I think the problem might be with the draw_class method, because I can't figure out how to output the class name as a strig. Here's the edit:

Code:
 

class Window_Class < Window_Selectable

  def initialize(width, index)

    super(0, 120, 320, 360)

    self.contents = Bitmap.new(width - 32, height - 32)

    @column_max = 1

    self.index = 0

    refresh

  end

  

  def refresh

    self.contents.clear

    @choices = []

    for i in 0..$data_classes.size

      classes = $data_classes[i]

      if classes != nil

        @choices.push(classes)

      end

    end

    @item_max = @choices.size

    if @item_max > 0

      for i in 0..@item_max

        draw_class(i)

      end

    end

  end

  

  def draw_class(index)

    classes = @choice[index]

    self.contents.draw_text(0, index * 32, 200, 32, classes.name)

  end

end

 
 
Okay... I put that in, but now I'm having trouble in the first line of def draw_class(index)

Code:
 

class Window_Class < Window_Selectable

  def initialize(width, index)

    super(0, 120, 320, 360)

    self.contents = Bitmap.new(width - 32, height - 32)

    @column_max = 1

    self.index = 0

    refresh

  end

  

  def refresh

    self.contents.clear

    @choices = []

    for i in 0..$data_classes.size

      classes = $data_classes.compact.map{|cl| cl.name }

      if classes != nil

        @choices.push(classes)

      end

    end

    @item_max = @choices.size

    if @item_max > 0

      for i in 0..@item_max

        draw_class(i)

      end

    end

  end

  

  def draw_class(index)

    [b]classes = @choice[index][/b]

    self.contents.draw_text(0, index * 32, 200, 32, classes[index])

  end

end

 
 
[rgss]@choices = []
     for i in 0..$data_classes.size
       classes = $data_classes.compact.map{|cl| cl.name }
       if classes != nil
         @choices.push(classes)
       end
     end
[/rgss]

nooooooooo


this is all you need
[rgss]@choices = $data_classes.compact.map{|cl| cl.name }
[/rgss]

and:
[rgss]   def draw_class(index)
     self.contents.draw_text(0, index * 32, 200, 32, @choices[index])
   end
[/rgss]
 
Ugh.... Okay, now this is what I have... I'm not getting this at all...

Code:
 

 def initialize(width, index)

    super(0, 120, 320, 360)

    self.contents = Bitmap.new(width - 32, height - 32)

    @column_max = 1

    self.index = 0

    refresh

  end

  

  def refresh

    self.contents.clear

    @choices = $data_classes.compact.map{|cl| cl.name }

    @item_max = @choices.size

    if @item_max > 0

      for i in 0..@item_max

        draw_class(i)

      end

    end

  end

  

  def draw_class(index)

    self.contents.draw_text(0, index * 32, 200, 32, @choices[index])

  end

end

 

I should mention that I really don't know much about RGSS... in case I didn't before.
 
It says there's a type error on line 22.

"cannot convert nil into String"

That's this line, in case it doesn't match up here:

self.contents.draw_text(0, index * 32, 200, 32, @choices[index])
 
Near":2mobibx0 said:
What's wrong with the current code? Can you post what is wrong, like a screenshot of the error(if there is one)?

Actually, the problem is that he's getting the error that he can't convert nil into a string. That would be because he is using the wrong number set to search the array. Change the following line:

Code:
self.contents.draw_text(0, index * 32, 200, 32, @choices[index])

To this line:

Code:
self.contents.draw_text(0, index * 32, 200, 32, @choices[index - 1])

Your problem was that you were searching the array with the wrong number sets. Arrays start with an index of 0, but your search started at 1 and ended 1 set beyond the end of the array, thus resulting in the program attempting to change a nonexistent value (nil) into a string. Now, if you were wondering what caused this, it would be the fact that the following lines:

Code:
      for i in 0..@item_max

        draw_class(i)

      end

Tell the code to use the draw_class(i) method several times, from when i == 1 to @item_max, which in this case equals 8. When you search the array in the draw_class(i) method, you need to find the correspoding values, which are actually found at the indices of 0..7, because an array starts at 0 instead of 1. And if you are wondering why the for i in 0..@item_max doesn't start at 0, it is because it skips the first number, and goes on to repeat until the last number.
 
Hmm... All right. The error is gone, but now I just have a logical error, and I'm assuming it has something to do with what you were talking about with searching... although I'm not sure which part of the code I should change
screenerror.jpg

The last entry isn't accessable (i.e. you can't cursor over it) even though Mage should be at the bottom, not the top.
 
PhoenixTilea":uvu3xnvq said:
Hmm... All right. The error is gone, but now I just have a logical error, and I'm assuming it has something to do with what you were talking about with searching... although I'm not sure which part of the code I should change
screenerror.jpg

The last entry isn't accessable (i.e. you can't cursor over it) even though Mage should be at the bottom, not the top.

Hmm...

Apparently the statement does start at 0. Change the for line to this:

Code:
for i in 0..(@item_max - 1)

And change the other line back to what you had before. So, it should look like this:

Code:
class Window_Class < Window_Selectable

  def initialize(width)

    super(0, 120, 320, 360)

    self.contents = Bitmap.new(width - 32, height - 32)

    @column_max = 1

    self.index = 0

    refresh

  end

  

  def refresh

    self.contents.clear

    @choices = $data_classes.compact.map{|cl| cl.name }

    p @choices

    @item_max = @choices.size

    if @item_max > 0

      for i in 0..(@item_max - 1)

        draw_class(i)

      end

    end

  end

  

  def draw_class(index)

    self.contents.draw_text(0, index * 32, 200, 32, @choices[index])

  end

end
 

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