Defining constant by game variable

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.
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?
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.
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. 🙂
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?
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?
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.
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.
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.
Never heard of that script writer.

Doesn't matter. The main thing is you got it working 😀
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?
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) 😛

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

Also, I have steam and skype ~ the name for both is 'DekitaRPG' 🙂
I might have need for a scripter for hire. 😉

Request sent on Steam.
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.
Drafyr please do not double post, edit your previous post if you've got something to add.
Sorry, won't happen again.
what is the purpose of a 'node'?
To be a gatherable resource with a limited amount of resources.

Original thread: https://forums.rpgmakerweb.com/threads/defining-constant-by-game-variable.38388/