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

Calling table arguements!?

Asked by
Kozero 120
10 years ago
piece=Workspace.Part
Hello={piece,"What?",true,76}
print (Hello[3])

Output =true

- Could I call the argument by their name for example

Hello["What"]

2 answers

Log in to vote
4
Answered by 10 years ago

No, it returns nil if you do that.

It's not needed though, as if you know the name of it, the easiest solution is to do something like this-

Hello = {piece,"What?",true,76}

for a,b in pairs(Hello) do
if b == "What" then

-- b is "What" in your table, code it as you wish
print(b.. " has been found")

end
end

What this does, basically, is will check each value of the table (as a generic for loop would), only giving any physical output when it gets to "What?".

Good luck, I tried to help! Please consider leaving an upvote!

0
Nice technique forgot I could do that. Kozero 120 — 10y
0
Thanks! Tortelloni 315 — 10y
Ad
Log in to vote
-1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

"What" is not a key in the table Hello.

I don't know what it is that you are asking.

object = {};
object["hi"] = 15;
print(object["hi"]); -- 15
print(object.hi); -- 15

other = {["hi"]=9};
print(other.hi); -- 9

some = {hi=2};
print(some.hi); -- 2

Answer this question