RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[RMXP] How to return the value of an in-game variable?

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 83
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.

Code: [Select]
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
Code: [Select]
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.

*
A Random Custom Title
Rep:
Level 96
wah
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.

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, to get the value of an in-game variable, just use:

Code: [Select]
$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:

Code: [Select]

    percentage = ((hp * 1.0) / max_rela)

If hp is undefined, you'll get an error. Plus you don't want the actor's hp.

**
Rep: +0/-0Level 83
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.
« Last Edit: May 22, 2010, 11:04:33 PM by AZN Skillz »