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

How to select what part of script to run.

Started by teg0r, 12 November 2014 - 08:06 AM
teg0r #1
Posted 12 November 2014 - 09:06 AM
So im trying to make script that builds tower, builds alvearys inside it, puts apiarys between alvearys and pipes alvearys. I made scripts for each of those and they worked but when im trying to make them into 1 script its not going too well. Here is the script http://pastebin.com/ngPfLpDE

Im trying to select what program to use on line 315-318


local program = 1
print("1=tower , 2=alvearys , 3=apiarys 4=pipes")
term.write("")
program = read()

and then i have



if program==1 then
elseif program==2 then
if program==3 then
elseif program==4 then

but for some reason when i type any number on read() its still going to run from "elseif program==2 then" and i have no idea why.
If someone has any ideas why this happens it would be great to get some help :D/>
Cycomantis #2
Posted 12 November 2014 - 09:16 AM
read() returns a string and you are comparing against a number so the checks fail.

Change you read() line to:

program = tonumber(read())
teg0r #3
Posted 12 November 2014 - 09:24 AM
Nice thanks alot dude:D Atleast i learned something today ^_^/>