Jump to content




Player Detector Issues


  • You cannot reply to this topic
4 replies to this topic

#1 Inumel

  • Members
  • 120 posts

Posted 12 June 2013 - 12:07 PM

Hello! Me again :P This time I am having issues with my player detector program

Here is the code http://pastebin.com/9wfD2u7q

The 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 ;-;

#2 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 12 June 2013 - 12: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 by Engineer, 12 June 2013 - 12:35 PM.


#3 Inumel

  • Members
  • 120 posts

Posted 12 June 2013 - 12:45 PM

Thank you sir! Works perfectly now :)

#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 12 June 2013 - 09: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.

#5 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 13 June 2013 - 12:46 AM

View Posttheoriginalbit, on 12 June 2013 - 09:21 PM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users