Jump to content


Photo

Renaming


  • Please log in to reply
3 replies to this topic

#1 lego_sniper

lego_sniper

    GMC Member

  • New Member
  • 899 posts

Posted 22 December 2007 - 06:22 PM

Is there a function or something that when you type a variable name in, and then another one in, it switches the two?
For example: If I type in 'lives' then 'player_health' I change the 'lives' variable name to 'player_health'.
  • 0

#2 sugaraddict

sugaraddict

    GMC Member

  • New Member
  • 37 posts

Posted 22 December 2007 - 09:04 PM

There is no function (THAT I KNOW OF, I am still new to GML) that does this. However, you can follow these steps...

Here is an example using variables "var1" and "var2" as the ones you want to switch:

1. Decide which 2 variables you want to switch (we have already decided on var1 and var2).

2. Create a 3rd variable (we will name it var3).

3. Set the value of "var3" to the current value of "var1."

4. Set the value of "var1" to the current value of "var2."

5. Set the value of "var2" to the current value of "var3."

The way this works is it save the value of var1, then turns var1 ino the second variable (var2), and then turns the second variable(var2) into the variable you saved in the beginning (var3).

Pretty simple, had to figure this out for a project of my own a long time ago...
  • 0

#3 mme

mme

    MME

  • GMC Member
  • 1007 posts

Posted 23 December 2007 - 06:12 AM

For global variables:
var a, b;
a=get_string("var to rename","global.var_lol")
if a !="" {b = get_string("Please type in a var to rename " +string(a)+ "","lol")}
if !variable_global_exists("var_lol") {show_message("Variable does not exist");}
else {if variable_global_exists("lol") {if show_question("The Variable " +string(b)+ " Exists#Would you like to overwrite it?") {variable_global_set(b,a)} 
else {show_message("variable not overwritten")}}}

For local variables:
var a, b;
a=get_string("var to rename","var_lol")
if a !="" {b = get_string("Please type in a var to rename " +string(a)+ "","lol")}
if !variable_local_exists("var_lol") {show_message("Variable does not exist");}
else {if variable_local_exists("lol") {if show_question("The Variable " +string(b)+ " Exists#Would you like to overwrite it?") {variable_local_set(b,a)} 
else {show_message("variable not overwritten")}}}

this is just a quick code there is probably a better way to do it :blink:

Edited by mme, 23 December 2007 - 06:17 AM.

  • 0

#4 lego_sniper

lego_sniper

    GMC Member

  • New Member
  • 899 posts

Posted 23 December 2007 - 02:20 PM

But wouldnt that make you able to change it whilst playing the game? I was thinking of chaning them while coding.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users