Jump to content




else statesment issue


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

#1 signur

  • Members
  • 3 posts

Posted 06 January 2014 - 08:16 AM

Hi,

As i am beginning to learn programation, and playing tekkit lite, i though of using computercraft to get familiarized with coding in a fun environment.
I'm basically a beginner.

In order to understand the code i went step by step, i'm now having fun with locks for doors.

Here is my attempt to make my lock, using iterative instead of recursive (or vice versa? i'm declaring function instead so that i can make my own library, it's iterative no?)


Spoiler

it tells me that i need a end to close the while loop.

I tryed many things ut as far as i know i don't need an extra end...

What did i do wrong?

Thanks in advance. :)

#2 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 06 January 2014 - 10:17 AM

In your if/then loop, you need to specify different statements with elseif, rather than another if.
Example:
if something then
    --do something
elseif somethingElse then
    --do something else
else
    --do something else entirely
end


#3 CometWolf

  • Members
  • 1,283 posts

Posted 06 January 2014 - 10:59 AM

The probelm is the end in this section
....if input == exit then
........term.clear()
........term.setCursorPos(1,1)
........shell.run "shell"
........end
....else
There's no need for an end to close an if statement if it's followed by an else or elseif statement.

#4 signur

  • Members
  • 3 posts

Posted 06 January 2014 - 02:03 PM

i manage to fix it by myself while the post was pending approval.

Here is the new version of my lock :

Spoiler

the issue resolved by itself. i understand that there was an end too much or missing.

I'll keep an eye on that.

little question before i end this topic (or am i allowed to follow the issue i encounter here?)

is there any way to get the console to close so that i don't have to hit escape ?

#5 MR_nesquick

  • Members
  • 106 posts
  • LocationNorway

Posted 06 January 2014 - 03:14 PM

delete
local input = password
and change out
password = read("*")
with
local input = read("*")
and you should be good to go
remember to change the "read()" inside the while loop

edit:
you can also do
while not input == password do
makes it easier to read :)


EDIT EDIT: where did joe's question go?

Edited by MR_nesquick, 07 January 2014 - 01:11 PM.


#6 signur

  • Members
  • 3 posts

Posted 06 January 2014 - 03:42 PM

View PostMR_nesquick, on 06 January 2014 - 03:14 PM, said:

delete
local input = password
and change out
password = read("*")
with
local input = read("*")
and you should be good to go
remember to change the "read()" inside the while loop


while not input == password do
makes it easier to read :)

EDIT EDIT: where did joe's question go?

could you give more explaination?

i'm not sure to follow.

#7 Bomb Bloke

    Hobbyist Coder

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

Posted 06 January 2014 - 04:32 PM

View Postsignur, on 06 January 2014 - 02:03 PM, said:

is there any way to get the console to close so that i don't have to hit escape ?
I believe not.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users