Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to give a variable two values?

Asked by 5 years ago

I need to know for a game but I do not know if it is even possible

4 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Yes, it is possible using tables, example:

Values = {"abc", "cba"} -- etc, you can do as much as you want.

You can learn more about tables Here

0
can you explain what those "abc" "cba" supposed to stand for? are they variables or location of what you wanted to lets say clone etc Platinum_Experience 0 — 5y
0
Just random string values, you can use pretty much anything like numbers Igoralexeymarengobr 365 — 5y
Ad
Log in to vote
0
Answered by 5 years ago
local MyArray = {"Fun!", 123}

Arrays can do what you need. They can infact carry an infinite amount of bools, strings, and integers.

0
aren't them called meta tables, or arrays lol? seems prety much the same Igoralexeymarengobr 365 — 5y
0
I dident know that there were metatables. I always called them arrays. RunKittenzRComin 170 — 5y
0
That's not a metatable, he doesn't know what he's talking about. That's just a table with an array-like structure. ScriptGuider 5640 — 5y
0
Yap, so to not complicate stuff, an array is just a table, and you can say that an array is the general name of this "structure", because it is named differently in each language, in lua they are called tables while in python for example they are called lists. But even with those different names, they are still an array. And for metatables, ScriptGuider here does actually have a good video on them starmaq 1290 — 5y
Log in to vote
0
Answered by
Lazarix9 245 Moderation Voter
5 years ago
local a, b, c = 1, 2, 3

print(a, b, c) --it will print '1 2 3'
print(a) -- it will print '1'
print(c, b) --it will print '3 2'

You get the point. Separate the Variable names by a comma, then separate the values by a comma and you will assign those values. There is also this method with tables:

local hi = {'hello', 3, 'stuff' }

but I don't really know how tables work so yeah. Sorry if this is not what you were looking for.

Log in to vote
0
Answered by
tomekcz 174
5 years ago

You can also do this

 local gun = {}
gun.Damage = 100
gun.BulletSpeed = 1
print(gun.Damage)

it will print "100"

when referring to Damage just do gun.Damage when referring to BulletSpeed just do gun.BulletSpeed

of course you can change the names and add more

Answer this question