Defining constant by game variable

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
I am trying to define a constant in a script to an in-game variable. I am not accomplishing my task. Here's what I'm doing.

SAID_VARIABLE = $game_variables[1]

Can someone help? It needs to be defined by a game variable.
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
No. just no. Wont happen.

Constants are read before any of the runtime variables are set - this includes $game_variables. Due to this single fact ~ you will never be able to set a constant to the value of a game variable. (unless your constant is not defined at startup for some reason)

Also ~ why would you want to?
 
Last edited by a moderator:

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
I am trying to make it so that you can gather a certain amount of times from a specific node, the node is defined as variable 1, then we use this value to determine which variable it corresponds to, for example node 2, would be variable 2. I then add 1 to it when a successful gather occurs. In order to do this, I need to figure out a way to define the variable in the script so that I can call and modify the value for displaying the current gather count and add to the count upon a successful gather. I am trying to modify reedo's simplified mining system. Here's what I have.

 

 

 

Code:
f  CURRENT_NODE = node  NODE_COUNTER = counter  def node    node = $game_variables[1]  end  def counter    counter = $game_variables[node]  # -------------------------------------------------------------------------  # Mining Gold  # -------------------------------------------------------------------------  def gold_mining    gold_counter = rand(GOLD_RANGE)      if gold_counter >= GOLD_SUCCESS        p gold_counter        RPG::SE.new(MINE_SUCESS,MINE_SE_VOL,MINE_SE_PITCH).play        $game_party.gain_item($data_items[GOLD_ITEM_ID],VALUE)        $game_variables[NODE_COUNTER] + 1        SceneManager.goto(Scene_Map)        $game_message.add("Current node counter is #{NODE_COUNTER + 1}")        dispose_image_cover      else        p gold_counter        SceneManager.goto(Scene_Map)        dispose_image_cover      end  end
Gonna test now.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
That will likely cause errors, there are many parts of code missing or incorrect from just that small part you have posted. :)

Also, you are attempting to set a constant to the value of a method before the method has been defined, this will also error. And the again, game_variables doesnt exist, so if you define the method beforehand, another error. :)
 
Last edited by a moderator:

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
It didn't work. Do you have any ideas of how to impliment what I tried doing? Defining a method, then using that method to define a constant?
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
Well, your approach wont work for the reasons detailed above.

Also, there is no need for a constant to be set ~ you are not gaining anything by using a constant.

What exactly are you trying to achieve with your code, cause I honestly cannot tell from the code you have posted. Like umm, what is the desired result?
 

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
I want to grab a variable value, use that value to define a variable to grab, and then add 1 to that variable upon successful gathering, then display a message with the current variable value.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
In order to use a variable to determine the id of another variable, you could do this...

$game_variables[$game_variables[1]]^ this would automatically contact the variable whos id is determined by the number stored within game variable 1.

In order to add 1 onto this variable, we could do this...

$game_variables[$game_variables[1]] += 1Finally, in order to show said variable within a message box, you should be able to do this within the text box (not tried, should work).

\V[\V[1]]So, putting that together with the code you showed previously you might end up with something like this... (not tried, might work)

VARIABLE_ID = 1 def gold_mining mine_success? ? successful_mine : failed_mine end def mine_success? rand(GOLD_RANGE) >= GOLD_SUCCESS end def successful_mine RPG::SE.new(MINE_SUCESS,MINE_SE_VOL,MINE_SE_PITCH).play $game_party.gain_item($data_items[GOLD_ITEM_ID],VALUE) $game_variables[$game_variables[VARIABLE_ID]] += 1 SceneManager.goto(Scene_Map) $game_message.add("Current node counter is \V[\V[#{VARIABLE_ID}]]") end def failed_mine SceneManager.goto(Scene_Map) end def dispose_main_viewport dispose_image_cover super endEdit:

Who wrote this script you are trying to alter, cause for lack of a better phase, its piss poor.
 
Last edited by a moderator:

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
It worked! However, I needed to put two \'s in the messages in order for it to do the variable call through a game_message script call.

It was made by Reedo.
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
Never heard of that script writer.

Doesn't matter. The main thing is you got it working :D
 

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
Yes! Thank to you! If I need more help, I will be sure to go to you. ;)

Do you have a chat program you use, or some way of contacting you directly through some means of real-time communication?
 
Last edited by a moderator:

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
If I need more help, I will be sure to go to you. ;)
Not really what I was suggesting, but uhh,  dont mind helping out now and then. Just gotta keep in mind, I'm almost always busy with a script that is likely more important to me than some other script (this is almost always the case) :p

Dont mean for that to sound rude or anything, its just, these kinda scripts dont interest me much anymore :D

Also, I have steam and skype ~ the name for both is 'DekitaRPG' :)
 

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
I might have need for a scripter for hire. ;)

Request sent on Steam.
 

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
Can you perhaps think of a better way to handle node gather count? So that I don't have to create tons of variables for each node?

There are at least 100+ nodes on just the first map, and I plan for there to be many maps.
 
Last edited by a moderator:

Celianna

Tileset artist
Veteran
Joined
Mar 1, 2012
Messages
10,557
Reaction score
5,592
First Language
Dutch
Primarily Uses
RMMV
Drafyr please do not double post, edit your previous post if you've got something to add.
 

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
Sorry, won't happen again.
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,513
Reaction score
3,203
First Language
Binary
Primarily Uses
RMMZ
what is the purpose of a 'node'?
 

Drafyr

Novice
Veteran
Joined
Apr 16, 2014
Messages
32
Reaction score
0
First Language
English
Primarily Uses
To be a gatherable resource with a limited amount of resources.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,860
Messages
1,017,038
Members
137,568
Latest member
invidious
Top