Author Topic: Tip: Control structure too long near  (Read 1321 times)

Zefk

  • Hero Member
  • *****
  • Posts: 536
  • Just helping Solarus
    • View Profile
    • Zelzec
Tip: Control structure too long near
« on: October 10, 2016, 06:56:30 am »
This can happen with too many if statements  are nested into one if statement.

Code: [Select]
Control structure too long near
Too many elseif statements in one if control structure can cause the same error.

Code: ( lua) [Select]
if X then
   -- stuff
elseif Y then
   -- stuff
elseif Z then
   -- stuff
end

Source:
https://forums.wowace.com/showthread.php?t=21768

It can happen with a loop too.

Code: ( lua) [Select]
local b="x=1;"
while true do
        local s="while true do "..b.." end"
        local f,err=loadstring(s)
        print(#b)
        if f==nil then
                print(#b,err)
                break
        end
        b=b..b
end

Source:
http://lua.2524044.n2.nabble.com/Cause-for-quot-control-structure-too-long-quot-td7650425.html

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1176
    • View Profile
Re: Tip: Control structure too long near
« Reply #1 on: October 10, 2016, 09:27:58 am »
If you reach this kind of limit, there is something really wrong with your code.

Zefk

  • Hero Member
  • *****
  • Posts: 536
  • Just helping Solarus
    • View Profile
    • Zelzec
Re: Tip: Control structure too long near
« Reply #2 on: October 10, 2016, 11:28:26 am »
I fixed it, so nothing is wrong with my script.