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.

[XP]Displaying a Variable ID's result when... [RESOLVED]

Looked around for a bit to find a topic on this and haven't seen one yet, so I guess it's time to post a topic. =P

Basically, I have Variables 0001 - 0014 set to display some information about a character (numerical). I have edited Window_Status to show this information, but I cannot get it to work. So the question is, how do I get it to take the actor's ID, and then return the result of the variable with the same ID as the actor? Thanks in advance.
 
Well, what you could of course do is this:
Code:
self.contents.draw_text(rect, $game_variables[@actor.id])
This is assuming you have an @actor variable, which you should in the mentioned scene.

The real question here is why you don't write another attribute to Game_Actor. Create a variable named @yourpurpose below all the others in initialize definition, and then attribute it (attr_accessor :yourpurpose) above that.
Having that done, you can display it like this:
Code:
self.contents.draw_text(rect, @actor.yourpurpose)
And change it in the first place like this:
Code:
@actor.yourpurpose = 12345
Obviously, you can refer to the actor any way you want... for example by database ID:
Code:
$game_actors[id].yourpurpose = 12345
Or party position:
Code:
$game_party.actors[n] = 12345 # n is position-1, meaning the first character is 0, the second 1, ...
 
None of that seemed to work. Here are the two lines of code I added to Window_Status in def_refresh...

Code:
self.contents.draw_text(400, 342, 180, 32, "Custom Parameter")

self.contents.draw_text(400, 374, 180, 32, $game_variables[@actor.id])

So basically while viewing a status screen, it should be referencing the actor's ID and then returning the result of the variable with the same ID. But it returns a "cannot convert Fixnum into string" error.
 
My bad... that always happens to me XD

Here goes your second line:
Code:
self.contents.draw_text(400, 374, 180, 32, $game_variables[@actor.id].to_s)

The explanation for that is that draw_text can only return strings, while $game_variables (normally) only contains integers. the .to_s command will actually convert an integer into a string, i.e. 2 => "2"
 
I'd really really suggest you to do it the other way though. It might seem a bit more work, but actually, you'll end up with a much more versatile system, nevermind the scripting knowledge you'll get.

But yeah, other than that... resolved, I guess.
 

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