Jump to content




couple questions.


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

#1 subzero22

  • Members
  • 97 posts

Posted 29 October 2014 - 03:28 AM

First off I'm on tekkit classic normally do direwolf20 but a friend just started mc and wanted to go on classic lol.

Why doesn't this work
if id == 7 or id == 15 and message == "close" then
do stuff
end

I got it working by doing this but why doesn't the top one work?
if id == 7 or id == 15 then
if message == "close" then
do stuff
end
end

My other question is I used to have a program running while at the same time have a passward program going. Kinda like have a server program running but if someone trieds to use the server computer will ask them a password before server shuts down so you can do stuff in it. I forgot how I did this and wondering how to do it again.

As in on the server computer itself if you click on it, it will ask you for a password but at the same time it will take/send commands from other ocmputers untill you enter the password to shut down the server script so you can work on it. this way someone can't just come and terminate it and edit it.

#2 Saldor010

  • Members
  • 467 posts
  • LocationThe United States

Posted 29 October 2014 - 03:36 AM

Not sure about the first question, but to answer your password program/regular program running at the same time question, you can use the parallel API.

And just do something like this.

function Program()
  ...
end
function Password()
  ..
end
parallel.waitForAny(Program,Password)


#3 Dragon53535

  • Members
  • 973 posts
  • LocationIn the Matrix

Posted 29 October 2014 - 03:52 AM

The first one is easy.

With the code you have, the computer sees this
if (id == 7) or (id == 15 and message == "close") then
In which case if the id is 7, and the message is whatever, then go on, or if the id is 15 and it's sending the message close, then go on.
You want it like this, and type it like this
if (id == 7 or id == 15) and message == "close" then
That way the computer is like, okay we're going to pair this 'and' with the result of the 'or', rather than the 'and' with the second option in the 'or'.

Edit: Afterthought, you might be able to get away with an 'and or' rather than the 'or and' you have.

Not sure if it's going to exactly work this way, however the way above will work
if message == "close" and id == 7 or id == 15 then

Nope just tested doesn't work D:

I'm an idiot, wrote my test code incorrectly and thus didn't get correct result. Yes this way does work.
As my college professor said, most errors in code are logic errors...

Edited by Dragon53535, 29 October 2014 - 04:00 AM.


#4 Cycomantis

  • Members
  • 60 posts

Posted 29 October 2014 - 03:53 AM

You need to check what the message is for both ID's.
if id == 7 and message == "close" or id == 15 and message == "close" then
do stuff
end

Edited by Cycomantis, 29 October 2014 - 03:54 AM.


#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 October 2014 - 07:23 AM

View PostCycomantis, on 29 October 2014 - 03:53 AM, said:

You need to check what the message is for both ID's.

Nah, that's really not necessary.

View PostDragon53535, on 29 October 2014 - 03:52 AM, said:

As my college professor said, most errors in code are logic errors...

And I guess that means the rest are illogical errors. That covers the spectrum pretty well, I reckon.

Edited by Bomb Bloke, 29 October 2014 - 09:50 AM.


#6 subzero22

  • Members
  • 97 posts

Posted 29 October 2014 - 09:21 AM

ok so all I had to do was add the ( and ) or am I missing something here?

#7 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 October 2014 - 09:52 AM

Personally, I'd use this line Dragon gave you:

if (id == 7 or id == 15) and message == "close" then

Easier for me to read later, given that I can never remember the order of operations in such cases. The brackets let you enforce 'em any way you want 'em.

#8 subzero22

  • Members
  • 97 posts

Posted 29 October 2014 - 10:51 AM

ah ok thanks





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users