CC: Tweaked

CC: Tweaked

42M Downloads

Unexepected "elseif" and "else" error.

Logotocom-OS opened this issue ยท 16 comments

commented

Hey, here's a bug.

I was trying out your copycat and using my code on the emulator since I don't have Java Minecraft yet, I discovered the issue, and it is going for simple code.

I kept on getting it, and it's likely not going to work with any programs that has "else" and "elseif". This error won't work and this will need a hotfix.

Suggesting to find the error with the else and elseif error. The error makes programs I make with Lua and the coding I know, makes my programs not work. Sorry, but I am suggesting a hotfix for you please. I may get improvement and fork it to make some improv.

commented

Can you share the code you are using?

commented

Alright. I been working on the code and I will share.
This is the boot api for my OS i am working on.

local function boot:PrintMSG( _sText , _sType )
  if _sType ~= error then
    if os.isColor() then
      term.setTextColor( colors.red )
    end
    print( "[ERROR] ["..os.time().."] ".._sText )
  elseif _sType ~= critical then
    if os.isColor() then
      term.setTextColor( colors.orange )
    end
    print( "[CRITICAL] ["..os.time().."] ".._sText )
  elseif _sType ~= warn then
    if os.isColor() then
      term.setTextColor( colors.yellow )
    end
    print( "[WARN] ["..os.time().."] ".._sText )
  elseif _sType ~= success then
    if os.isColor() then
      term.setTextColor( colors.lime )
    end
    print( "["..os.time().."] ".._sText )
  elseif _sType ~= none then
    term.setTextColor( colors.white )
    print( "["..os.time().."] ".._sText )
  else
    term.setTextColor( colors.white )
    print( "["..os.time().."] ".._sText )
  end
  term.setTextColor( colors.white )
end
commented

And what's the error you receive? I'm 99.999% confident there's nothing wrong with else and elseif, and that the problem is actually your code. As a note, these are used in bios.lua and shell.lua - so if you've broken something in your fork, that's on you.

commented

I'll run the code again and see the error.

commented
if _sType ~= error then

Are error etc. supposed to be in quotes? You've named the variable _s which would indicate its a string, and I don't see you declaring error as a variable anywhere (though you might do this elsewhere). Try this:

if _sType ~= "error" then
commented

Oh thanks. I ran my code and I have put the quotes in there, it might of cut off the quotes in the paste.

commented

Found a issue in the boot code. It says expected ''end''. The else and elseif does not require that.

commented

I did it by using my OS boot I am working on.

commented

100% a syntax error on your end, nothing wrong with CC:T. Show the exact code and the line it occurs on, as well as a screenshot of the actual error message. As a side note:

local function boot:PrintMSG

This is invalid. A local function cannot use :, only regular functions can. Change it to this:

function boot:PrintMSG
commented

I wish I could but I have a Kindle which I am using, and it's slow.
I been looking at the Lua coding guide, and I will change the API error. I'll change it from boot:PrintMSG() to api.PrintMSG() and fully call it as a API as I just looked up how the API code works excactly.

commented

Oh and I'm grabbing my code out.

commented

For api.PrintMSG() you still need to remove local.

commented

Ok I gotcha. Through the GUI api I am using from someone who created, and here's my code I did here

os.loadAPI("gui.lua")

local dir = "/gdprokidOS/startup/start.lua"

function bootSequence()
  -- Wait for a key event:
	local event, key = os.pullEvent()
	
	-- Act on key press
	if key == "keys.enter" and x < xSize then
    shell.run( dir )
    gui.clearAllObjects()
        end
	if key == "keys.F1" or gui.getButtonState( "cancel-button" ) == true then
    gui.setLabelText( "load-label" , "Canceling boot..." )
    os.sleep(1)
    gui.clearAllObjects()
    term.setCursorPos(1,1)
    print( "Canceled direct boot to" )
    print( "/CraftOS" .. dir )
    os.sleep(2)
    term.clear()
    term.setCursorPos(1,1)
    print( "To boot, type \"reboot\"." )
    print( "Boot System" )
    shell.exit()
		break
	end
  gui.updateAll()
end

local w, h = term.getSize()
local prog = 100
local timer = 0

gui.newLabel( "title-1" , "Boot System" , 1 , 1 , w - 8 , 1 , colors.blue )
gui.newButton( "cancel-boot" , "Cancel", w - 8 , 1 , 8 , 1, nil, nil, colors.pink, colors.red, false)

gui.newLabel( "boot-dir-title" , "Boot Directory" , 2 , 3 , w - 2 , 1 , colors.blue )
gui.newLabel( "boot-dir" , "/CraftOS" .. dir , 2 , 5 , w - 2 , 2 , colors.gray )
gui.newBar( "load-bar" , 1 , h - 2 , w , 1 , colors.lightBlue , colors.blue , 0)
gui.newLabel( "load-label" , "Loading..." , 1 , h - 3 , w , 1 , colors.blue )
os.sleep(0.01)
gui.setLabelText( "load-label" , "Press F1 to cancel. Press enter to boot." )

gui.updateAll()
timer = 5
repeat
  bootSequence()
  os.sleep( 0.01)
  timer = timer - 0.01
until timer < 0.01
repeat
  bootSequence()
  gui.setBarValue( "load-bar" , prog )
  gui.setLabelText( "load-label" , "Booting  OS in " .. math.round(prog / 10) .. " seconds..." )
  prog = prog - 0.1
  os.sleep(0.01)
until prog < 1

gui.clearAllObjects()

shell.exit()
commented

It may have a lot of error I am aware of.

commented

This has become programming advice now, and is definitely not suited for the CC:Tweaked issue tracker. Please close this issue and take it to Ask a Pro on the forums.

commented

So thank you and I will close the issue. Glad for your help.