Too Many Syntax Levels Error

I’m trying to put a bunch of variables into a text file. I had 77 Variables at one point and everything worked fine. I just added 36 more and I now get a ‘Too Many Syntax Levels’ error. What’s wrong?Any Help would be appreciated. Thanks.

local composer = require("composer") local scene = composer.newScene() local file local i=1 path = system.pathForFile("test3.txt",system.DocumentsDirectory) if file then composer.gotoScene("kite") else file=io.open(path,"w") file:write("red".."\n".."red".."\n".."red".."\n".."red".."\n".."red".."\n".."red".."\n".."red".."\n".."red" .."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n" .."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n" .."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n" .."2".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n" .."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".. "\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n" .."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n" .."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0".."\n".."0") io.close(file) composer.gotoScene("forward") end

I would guess it’s all that concatenation you are doing. It appears that none of it is necessary.

This:                                       “red”…"\n"…“red”…"\n"…“red”

Is the same as this:                “red\nred\nred”

So maybe getting rid of all the concatenation will solve your problem.

Thanks Hasty for the response but I did try that already and it didn’t work. I just noticed a slight difference in what I tried and what you typed, so I will test out what you posted and see if it works. Thanks again.

Unless I’m mistaken, all that catenation is going to kill your performance and stress the limits of Lua.

For example, this statement produces 5 temporary strings (“1”, “2”, “3”, “12”, and finally “123”):

local a = "1" .. "2" .. "3"

This is a huge waste of CPU and memory.  Using tables is MUCH MUCH MUCH… better.

Better is to do this:

  1. (required step) Download these files:

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/io.lua

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/string.lua

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/table.lua

  1. (required step) Put them in your project in a subfolder  named _ extensions _

Tip: If you try to use thes files from the root folder this won’t work, because the file names are the same as known libraries.

  1.  (required step)One time only (usually near the top of main.lua) do this:

    require “extensions.io” require “extensions.string” require “extensions.table”

  2. Now, save you variables in a table and save/restore the table.

Method 1 (Positional Values)

-- This example assumes you required the extensions previously -- as shown above. -- -- Storing positional data to save and retrieve later -- For example colors of gems, or something like that. -- -- 1. Fill the table local toSave = {} toSave[#toSave+1] = "red" toSave[#toSave+1] = "red" toSave[#toSave+1] = "red" toSave[#toSave+1] = "green" toSave[#toSave+1] = "red" toSave[#toSave+1] = "blue" -- 2. Print contents for prove the future code works for i = 1, #toSave do print(i,toSave[i]) end -- 3. Save the table. table.save( toSave, "myGemColors.txt" ) -- Use an extension of .txt, .json, or other you want. -- 4. Later you can restore it like this: local restoredData = table.load( "myGemColors.txt" ) -- 5. Now print the restore to see it worked for i = 1, #restoredData do print(i,restoredData [i]) end

Method 2 (Named Values)

Another common way to use tables is to store ‘settings’ ,etc.

-- This example assumes you required the extensions previously -- as shown above. -- -- Storing named data via a table (like game settings). -- -- 1. Fill the table local gameSettings = {} gameSettings.soundEn = true gameSettings.lives = 3 gameSettings.playerName = "Bob" -- 2. Print contents for prove the future code works (print order is random) for k,v in pairs( gameSettings ) do print( k, v ) end -- 3. Save the table. table.save( gameSettings , "settings.json" ) -- 4. Later you can restore it like this: local restoredSettings = table.load( "myGemColors.txt" ) -- 5. Now print the restore to see it worked (print order is random) for k,v in pairs( restoredSettings ) do print( k, v ) end

Thanks RoamingGamer for the response. I think I may have those extensions already.  The above code just sets up all the variables and makes sure there is a text file with those variables in it. When I read the text file into the game I put those variables into a table. You just can’t see that because its on the next composer page. But after looking at some of your examples I like the local restoredData = table.load( “myGemColors.txt” ) I will try and incorporate it. Thanks again. Your information was helpful.

I would guess it’s all that concatenation you are doing. It appears that none of it is necessary.

This:                                       “red”…"\n"…“red”…"\n"…“red”

Is the same as this:                “red\nred\nred”

So maybe getting rid of all the concatenation will solve your problem.

Thanks Hasty for the response but I did try that already and it didn’t work. I just noticed a slight difference in what I tried and what you typed, so I will test out what you posted and see if it works. Thanks again.

Unless I’m mistaken, all that catenation is going to kill your performance and stress the limits of Lua.

For example, this statement produces 5 temporary strings (“1”, “2”, “3”, “12”, and finally “123”):

local a = "1" .. "2" .. "3"

This is a huge waste of CPU and memory.  Using tables is MUCH MUCH MUCH… better.

Better is to do this:

  1. (required step) Download these files:

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/io.lua

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/string.lua

http://github.com/roaminggamer/SSKCorona/blob/master/ssk/extensions/table.lua

  1. (required step) Put them in your project in a subfolder  named _ extensions _

Tip: If you try to use thes files from the root folder this won’t work, because the file names are the same as known libraries.

  1.  (required step)One time only (usually near the top of main.lua) do this:

    require “extensions.io” require “extensions.string” require “extensions.table”

  2. Now, save you variables in a table and save/restore the table.

Method 1 (Positional Values)

-- This example assumes you required the extensions previously -- as shown above. -- -- Storing positional data to save and retrieve later -- For example colors of gems, or something like that. -- -- 1. Fill the table local toSave = {} toSave[#toSave+1] = "red" toSave[#toSave+1] = "red" toSave[#toSave+1] = "red" toSave[#toSave+1] = "green" toSave[#toSave+1] = "red" toSave[#toSave+1] = "blue" -- 2. Print contents for prove the future code works for i = 1, #toSave do print(i,toSave[i]) end -- 3. Save the table. table.save( toSave, "myGemColors.txt" ) -- Use an extension of .txt, .json, or other you want. -- 4. Later you can restore it like this: local restoredData = table.load( "myGemColors.txt" ) -- 5. Now print the restore to see it worked for i = 1, #restoredData do print(i,restoredData [i]) end

Method 2 (Named Values)

Another common way to use tables is to store ‘settings’ ,etc.

-- This example assumes you required the extensions previously -- as shown above. -- -- Storing named data via a table (like game settings). -- -- 1. Fill the table local gameSettings = {} gameSettings.soundEn = true gameSettings.lives = 3 gameSettings.playerName = "Bob" -- 2. Print contents for prove the future code works (print order is random) for k,v in pairs( gameSettings ) do print( k, v ) end -- 3. Save the table. table.save( gameSettings , "settings.json" ) -- 4. Later you can restore it like this: local restoredSettings = table.load( "myGemColors.txt" ) -- 5. Now print the restore to see it worked (print order is random) for k,v in pairs( restoredSettings ) do print( k, v ) end

Thanks RoamingGamer for the response. I think I may have those extensions already.  The above code just sets up all the variables and makes sure there is a text file with those variables in it. When I read the text file into the game I put those variables into a table. You just can’t see that because its on the next composer page. But after looking at some of your examples I like the local restoredData = table.load( “myGemColors.txt” ) I will try and incorporate it. Thanks again. Your information was helpful.