generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Help

Previous Thread :: Next Thread 
Robloxmaster2137 is not online. Robloxmaster2137
Joined: 30 Jan 2011
Total Posts: 281
20 May 2013 02:55 AM
How can I get this to print a as val1/2/3 instead of printing the integer?

val1 = 1
val2 = 2
val3 = 3

a = math.max(val1,val2,val3)
print(a)
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
20 May 2013 03:02 AM
val1 = 1
val2 = 2
val3 = 3

a = math.max(val1,val2,val3)
print("val"..a)
Report Abuse
Robloxmaster2137 is not online. Robloxmaster2137
Joined: 30 Jan 2011
Total Posts: 281
20 May 2013 03:05 AM
Well what I mean is if it is possible to change an integer back to its variable state after doing this, for example...

cheese = 1
bananas = 2
choc = 3


because they are not necessary have integers at the end of the variable...
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
20 May 2013 03:15 AM
You could do this

function GetVarName(value)
for num,obj in pairs(getfenv(0)) do
if obj == value then
return num
end
end

val1 = 1
val2 = 2
val3 = 3

a =GetVarName( math.max(val1,val2,val3))

print(a)


This might not work as expected, if you'll have variables with same value.
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
20 May 2013 03:15 AM
Missed one end.

Report Abuse
Robloxmaster2137 is not online. Robloxmaster2137
Joined: 30 Jan 2011
Total Posts: 281
20 May 2013 03:23 AM
Thank you it works, I'm reasonably new to scripting so sorry for asking you to make me something instead of help :)


Thanks again!
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
20 May 2013 03:30 AM
For more accurate results, you can do:

t = {}
t.var1 = 1
t.var2 = 2
t.var3 = 3

function GetVarName(value,t)
for num,obj in pairs(t) do
if obj == value then
return num
end
end
end


print(GetVarName(math.random(3),t))


Still it will get first equal value it finds in table.

Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image