This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Robbo5899's profile picture

Variables

Started by Robbo5899, 19 April 2013 - 10:32 AM
Robbo5899 #1
Posted 19 April 2013 - 12:32 PM
I am trying to have a system that prints to a screen "player name" is logged in. I am using the player detector from Misc Peripherals. I want the monitor to show "player" is logged in only when certain people click the detector otherwise I want it to say "nobody is logged in". I thought the easiest way to do this would be using a variable although I'm not too sure how to do this.

I have included the code I currently have below.

All help would be greatly appriciated. I'm sorry if I haven't included enough detail please just ask if you think you might be able to help

http://pastebin.com/3eseuwrz
Sariaz #2
Posted 19 April 2013 - 01:00 PM
It looks like this code should do what you want. What problem do you have with the code as it is? Also you don't need to set score to one or zero just put the logout function were you currently set score to zero.
SuicidalSTDz #3
Posted 19 April 2013 - 01:17 PM
p = peripheral.wrap("left")
mon = peripheral.wrap("top")

while true do
 local ev, player = os.pullEvent("player")
 mon.clear()
 mon.setCursorPos(1,1)
 if player == "robbo5899" or player == "ScottCraigz121" then
  mon.write(player.." is logged in")
 else
  mon.write("Nobody is signed in")
 end
end

Functions are not needed in this script. I have taken the liberty of compacting your code for you.
Robbo5899 #4
Posted 19 April 2013 - 08:39 PM
[quote name='SuicidalSTDz' timestamp='1366373879' post='111861]

Functions are not needed in this script. I have taken the liberty of compacting your code for you.
[/quote]

I had put it into functions because i will be adding more thing for it to do when certain people are logged in. The program is still at an early stage but I see why you would want to do it like that. Thanks
SuicidalSTDz #5
Posted 19 April 2013 - 08:44 PM
Your only real problem was your comparison. You can add the functions back in, obviously.

This:
if b == ("robbo5899") or ("ScottCraigz121") then

Should've been this:
if b == ("robbo5899") or b == ("ScottCraigz121") then

Oh, and this:
mon.setCursoPos(1,1)

Should've been this:
mon.setCursorPos(1,1)

EDIT: The editor seems to have messed with the b variable
Fixed :P/>
robhol #6
Posted 19 April 2013 - 09:14 PM
Also, those parentheses shouldn't be there. Parentheses are for grouping operators and calling functions.
theoriginalbit #7
Posted 19 April 2013 - 09:23 PM
Also, those parentheses shouldn't be there. Parentheses are for grouping operators and calling functions.
They can be there, being there wont cause any errors. if it was me I would just move the opening bracket, since it can mentally help with brackets there.

if (b == "robbo5899") or (b == "ScottCraigz121") then