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

[programming] [menu] API: bios:278: bad argument: string expected, got nil

Started by Goof, 23 September 2012 - 08:19 AM
Goof #1
Posted 23 September 2012 - 10:19 AM
Hey!

i have a problem, during a code.

i've maded an API called "MikkelAPI" in that api, i'd make an function called "Continue1()"
But. when it launch the api, it just says:bios:278: bad argument: string expected, got nil


ehm why??



can someone help me out of this???




my code is here:


SpoilerCode that runs the api and other functions:
Spoiler


---[[ SECTION: VARIABLES

D1 = "-"
D2 = "-"
D3 = "-"
D4 = "-"
D5 = "-"
D6 = "-"
D7 = "-"
D8 = "-"
D9 = "-"
D0 = "-"
DX1 = "!"
DX2 = "!"
loop1 = true
loop2 = false
loop3 = false
loop4 = false
loopLogin1 = false
loopLogin2 = false
OptionC = 0
OptionB = 0
Line1 = 0
Line2 = 0
Line3 = 0
Line4 = 0

---]] SECTION: VARIABLES


---[[ SECTION: MENU

function menu1(id, text)
if Line1 == id then
write"-> "
elseif Line1 == 1 then
write" "
end
print(text)
end

function menu2(id, text)
if Line2 == id then
write"-> "
elseif Line2 == 1 then
write" "
end
print(text)
end

function menu3(id, text)
if Line3 == id then
write"-> "
elseif Line3 == 1 then
write" "
end
print(text)
end

---]] SECTION: MENU


---[[ SECTION: LOGIN

while loop1 do
term.clear()
term.setCursorPos(2,1)
menu1(0, "Login")
term.setCursorPos(2,2)
menu1(1, "Exit")
event, key = os.pullEvent("key")
if key == 200 then
if Line1 > 0 then
Line1 = Line1 - 1
end
elseif key == 208 then
if Line1 < 1 then
Line1 = Line1 + 1
end
elseif key == 28 then
if Line1 == 0 then --Login System Automation
loop1 = false
loopLogin1 = true
while loopLogin1 do
term.clear()
term.setCursorPos(1,1)
print("+------------------+")
print("+ Enter Username:  +")
print("+------------------+")
sleep(2)
term.setCursorPos(1,2)
term.clearLine()
term.setCursorPos(1,2)
print("+				  +")
term.setCursorPos(3,2)
UserName = read()
if UserName == "Admin1" then
sleep(0.6)
term.setCursorPos(1,2)
print("+ Checking input.  +")
sleep(2)
term.setCursorPos(1,2)
print("+ Username Found!  +")
sleep(1)
term.setCursorPos(1,2)
print("+ Welcome "..UserName.."   +")
sleep(1.6)
loopLogin1 = false
loopLogin2 = true
loop2 = true
while loopLogin2 do
while loop2 do

term.clear()
term.setCursorPos(1,1)
print("+------------------+")
print("+ Enter Password!  +")
print("+------------------+")
sleep(2)
term.setCursorPos(1,2)
print("+				  +")
term.setCursorPos(3,2)

PassWord = read("#")
if PassWord == "0903" then


term.setCursorPos(1,2)
print("+ Checking Input!  +")
sleep(2)
term.setCursorPos(1,2)
print("+ Password Correct +")
sleep(2)
term.setCursorPos(1,2)
print("+ Booting Startup  +")
sleep(2)

os.loadAPI( MikkelAPI.Continue1(1,1) )		-- HERE IS THE PROBLEM! --
loop1 = false
loop2 = false
loopLogin2 = false
elseif PassWord ~= "0903" then
term.setCursorPos(1,2)
print("+ Checking Input!  +")
sleep(2)
term.setCursorPos(1,2)
print("+ Input Incorrect! +")
sleep(1.7)
loopLogin2 = true
loop2 = true
end

end
loop2 = true
loopLogin2 = true

end
elseif UserName ~= "Admin1" then
sleep(0.6)
term.setCursorPos(1,2)
print("+ Checking input.  +")
sleep(1.7)
term.setCursorPos(1,2)
print("+ Input Not found! +")
sleep(1)

loopLogin1 = true
end

end

elseif Line1 == 1 then
os.shutdown()
end
loop1 = true

end
end

---]] SECTION: LOGIN

The API code:

Spoiler


---[[MikkelAPI.Continue()]]---

function Continue1(a1,a2)
term.clear()
term.setCursorPos(a1,a2)
print("+------------------------+")
print("+						+")
print("+------------------------+")


end


makerimages #2
Posted 23 September 2012 - 10:24 AM
i would suggest making a api and loading it with os.loadAPI(API FILEPATH HERE)
and calling Continue1() as so: APINAMEHERE.Continue1()
Goof #3
Posted 23 September 2012 - 10:31 AM
ehm.. i cant just make it like i did here?or anything else? just because that i'm not that good, creating APIS
makerimages #4
Posted 23 September 2012 - 10:33 AM
well, coding functions inside your program aint very practical. and APIS are not that hard, just copy the Continue1() function and youre done!
Goof #5
Posted 23 September 2012 - 10:36 AM
can i do it like this: os.loadAPI("MikkelAPI.Continue1()")
Goof #6
Posted 23 September 2012 - 10:41 AM
but…. when i launch the CC Emulator and entered the password, it still just keeps repeating the "Enter Password" it dosent stop that… why?
Goof #7
Posted 23 September 2012 - 10:49 AM
now it did start the new API, but…. now after that "+——————————+" then it says "Bios:268: Bad argument: string expected, got nil" what the ….?
Fatal_Exception #8
Posted 23 September 2012 - 11:16 AM
os.loadAPI("MikkelAPI")
Goof #9
Posted 23 September 2012 - 11:24 AM
then it just repeats the "Enter Password", and dont start the api…. :P/>/>
Fatal_Exception #10
Posted 23 September 2012 - 11:37 AM
Loading the API doesn't call the function, it just makes the function available to your program. You still have to call it where you need it.
Goof #11
Posted 23 September 2012 - 11:44 AM
so i need to do this?

os.loadAPI("MikkelAPI.Continue()")
Goof #12
Posted 23 September 2012 - 11:49 AM
but i dont know, how i can exit the "while loopLogin2 do" repeating system… it dosent stop it when i turn the loop into false…
sjele #13
Posted 23 September 2012 - 12:18 PM
Try sticking a break in there. On the line/part were you want it to quit the loop. (MUST be on the line before a new keyword, example.


while looploging2 do
if PassWord == "Correct" then
print("Correct:")
break
elseif password == "Wrong" then
print("wrong")
end
end
Goof #14
Posted 23 September 2012 - 12:37 PM
but…. i dont have any loop to repeat…. it says: bios:206: [string "startup4"]:103: no loop to break
sjele #15
Posted 23 September 2012 - 12:54 PM
Is the loop inside a while something do loop? If so try to remove the something = false in the part were you want it to break/quit
makerimages #16
Posted 23 September 2012 - 03:57 PM
you call the api after loading it like so:

APINAME.FUNCTION()