115 posts
Posted 12 June 2013 - 01:07 PM
Hello! Me again :P/> This time I am having issues with my player detector program
Here is the code
http://pastebin.com/9wfD2u7qThe issue I am having is, when a player right clicks the player detector it does nothing, doesn't say anything, just ends the program!
I am sure I am doing something obviously wrong.. But I cannot for the life of me figure it out :s
The name file is just as follows
{"name1"
"name2"
"name3"
}
yes I tried restarting the computer this time :P/>The closing of the files hasn't happened yet as I am still writing the program, don't yell at me ;-;
1522 posts
Location
The Netherlands
Posted 12 June 2013 - 01:34 PM
Are you sure your monitor is on the right side? Other then that it should work.
Oh, found another problem:
if playerr == names[1] or names[2] or names[3] then
this wont work the way you want, you must type a lot when you are programming :P/>
if playerr == names[1] or playerr == names[2] or playerr == names[3] then
Or if you are to lazy to do that you could do:
local found = false
for i = 1, #names do
if playerr == names[i] then
found = true
end
end
if not found then
print("Bye!")
end
Edited on 12 June 2013 - 11:35 AM
115 posts
Posted 12 June 2013 - 01:45 PM
Thank you sir! Works perfectly now :)/>
7508 posts
Location
Australia
Posted 12 June 2013 - 10:21 PM
Or even better (Engineer you need to get used to this :P/>)
define the table in the file like this
{["user1"] = true,["user2"] = true,["someone awesome"] = true,}
obviously with name values in there.
The reason for adding the `= true` is so that instead of this (code that Engineer posted)
for i = 1, #names do
if playerr == names[i] then
found = true
end
end
you can do this
found = names[playerr]
Why would you want to do this? Well if you have too large a table it can crash your program with a failure to yield (granted it would need to be a MASSIVE table, but it is still possible) and avoiding loops by doing a direct lookup is more efficient and much quicker in execution.
1522 posts
Location
The Netherlands
Posted 13 June 2013 - 01:46 AM
Or even better (Engineer you need to get used to this :P/>/>)
define the table in the file like this
{["user1"] = true,["user2"] = true,["someone awesome"] = true,}
obviously with name values in there.
The reason for adding the `= true` is so that instead of this (code that Engineer posted)
for i = 1, #names do
if playerr == names[i] then
found = true
end
end
you can do this
found = names[playerr]
Why would you want to do this? Well if you have too large a table it can crash your program with a failure to yield (granted it would need to be a MASSIVE table, but it is still possible) and avoiding loops by doing a direct lookup is more efficient and much quicker in execution.
Okay… :P/>