The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: AZN Skillz on May 22, 2010, 12:59:22 PM

Title: [RMXP] How to return the value of an in-game variable?
Post by: AZN Skillz on May 22, 2010, 12:59:22 PM
This is more of a scripting issue, so I'm not sure if this is in the right place. I'm using Tsuno's bar script to draw hp bars and such. In our game we recently added a relationship system, like from Dragon Age (thanks Mr Wiggles for helping with this  :)). In the Status window of the menu, I'm trying to have a bar that shows how well your relationship with the princess is.

I just can't figure out a way to return the value of an in-game variable (the ones controlled with the Control Variables action). The variable used to determine your relationship is controlled with events and Control Variables.


def draw_relationship_bar(actor,x,y,width = 140)
    rela = return @data[86]
    max_rela = 100
    percentage = ((hp * 1.0) / max_rela)
    bar_width = (percentage * width)
    empty_width = (width - bar_width)
    gray = Color.new(50,50,50,255)
    rela1 = Color.new(248,45,30,255)
    rela2 = Color.new(248,116,30,255)
    rela3 = Color.new(247,154,30,255)
    rela4 = Color.new(245,203,30,255)
    rela5 = Color.new(247,231,30,255)
    rela6 = Color.new(243,247,30,255)
    rela7 = Color.new(199,247,30,255)
    rela8 = Color.new(138,247,30,255)
    rela9 = Color.new(111,247,30,255)
    rela10 = Color.new(79,247,30,255)
    rela11 = Color.new(51,247,30,255)
    #draw empty if any
    self.contents.draw_gradient(x + bar_width,y,empty_width - 1,10,[gray])
    #draw gradient
    self.contents.draw_gradient(x,y,bar_width,10,[rela1,rela2,rela3,rela4,rela5,rela6,rela7,rela8,rela9,rela10,rela11])
    #draw border
    self.contents.fill_rect(x,y,width,1,Color.new(0,0,0,255))
    self.contents.fill_rect(x,y,1,10,Color.new(0,0,0,255))
    self.contents.fill_rect(x + width,y,1,10,Color.new(0,0,0,255))
    self.contents.fill_rect(x,y + 9,width,1,Color.new(0,0,0,255))
  end
end


Another thing is...the bar itself doesn't actually show up. I've tried using
if actor_id = 2
draw_hp_bar (using hp bar as a test, and no, the bar doesn't show up even with the arguments)


Any help is appreciated.
Title: Re: [RMXP] How to return the value of an in-game variable?
Post by: Kokowam on May 22, 2010, 02:59:42 PM
Jeez, you could at least look around a bit. >_>

Go to the scripts section and then go to the sticky'd thread called "Read this before asking about how to script RGSS."

Scroll down to the "RGSS References" link in the first post.

You should know what to do from there.
Title: Re: [RMXP] How to return the value of an in-game variable?
Post by: modern algebra on May 22, 2010, 05:41:38 PM
Well, to get the value of an in-game variable, just use:


$game_variables[x]


where x is the ID of the variable you want.

As for why the bar isn't showing up... it could be because you have "if actor_id = 2" when it should be if "actor.id == 2", but there might be other problems anyway. For instance, what is hp in this line:



    percentage = ((hp * 1.0) / max_rela)


If hp is undefined, you'll get an error. Plus you don't want the actor's hp.
Title: Re: [RMXP] How to return the value of an in-game variable?
Post by: AZN Skillz on May 22, 2010, 11:01:03 PM
Thanks for the help....and hp is supposed to be rela, I must have forgot to change it when I copied the script. I used the same script for HP, MP, and the relationship.