Jump to content

[HELP] Chunk has too many syntax levels


koragg

Recommended Posts

Just today I thought I'd do a live lyrics script for a new map I'll be making later on. I wanted to make it all about Linkin Park's Chester Bennington as I really loved his songs and grew up with him, was totally sad when he died so suddenly :( Anyway, it all worked out awesome until I got a "chunk has too many syntax levels" error and...well...dead end. I googled it and nothing useful for my case came up. What's wrong with it? I won't post the whole code here as it's around 500 lines in this file but here's the part of it which gives the error:

setTimer(function()
	addEventHandler("onClientRender", root, a111)
	setTimer(function()
		addEventHandler("onClientRender", root, a112)
		setTimer(function()
			addEventHandler("onClientRender", root, a113)																																																																																																		
		end, 300, 1)
	end, 300, 1)
end, 300, 1)

The error gives the line inside the innermost timer (a113) as the culprit but it's the same as any other line in my code.

Basically I use hundreds of timers to add event handlers and draw the dxtext with the lyrics on time. Please I really want to finish this map/project/script but am stuck with this error :\

Link to comment
  • Administrators

Possibly something to do with adding so many onClientRender events?

Just out of interest, why do you need so many different render events? It seems incredibly inefficient.

Why not just have 1 render event and use timers to know which lyrics to show on screen

Edited by LopSided_
  • Like 1
Link to comment
5 hours ago, LopSided_ said:

Possibly something to do with adding so many onClientRender events?

Just out of interest, why do you need so many different render events? It seems incredibly inefficient.

Why not just have 1 render event and use timers to know which lyrics to show on screen

I have each word in a separate function. So that way when i add an event handler to a function it shows just one word, not the whole sentence. Can't find an example on YouTube but i hope you understood me xd. I show each word on the screen exactly when you'd hear it in the song. 

Link to comment
  • Administrators

That's a bad way to do it.

Instead of each word inside a function, store your words/lyrics in a table and have 1 render function which works out by getTickCount (or timers) which lyric to show on the screen. Much easier and not to mention more efficient.

Edited by LopSided_
  • Like 1
Link to comment
41 minutes ago, LopSided_ said:

That's a bad way to do it.

Instead of each word inside a function, store your words/lyrics in a table and have 1 render function which works out by getTickCount (or timers) which lyric to show on the screen. Much easier and not to mention more efficient.

Continueing in new files whenever the error comes fixes it. Well, it's easier if you know how to do it :D I'm not good neither with tables nor getTickCount() (idk when and how to use it). Thanks though, will have that in mind for the future. :)

Link to comment

Well, use one function and one var which will be the dx text's text and set a hundered timers which change the var value, that is easier I think. Something like that;

local

local var = ""

addEvenHandler("...",root,function()
    dxDrawText(var,sx,sy,w,h...)
end)

setTimer(function()
    var = "One word"
end,6000,1)

-- you can make one timer too if u use tables, but since you dont use them just make a hundered timer.

 

  • Thanks 1
  • Haha 1
Link to comment
  • Administrators

Here's a small example

local lyrics = {
  {time=2000,words="This is the first line"}, --These lyrics show for 2000ms (2 seconds), then moves to next.
  {time=1000,words="Second line"}, --Same again here, they show for 1000ms (1 second) then moves to next
  {time=5000,words="Some more awesome lyrics"},
  {time=3500,words="I like turtles"}
}

local currentLyric = 0
local tick

function renderLyrics()
  local currentLyricTime = lyrics[currentLyric].time --How long should the current lyric display for?
  if getTickCount() > tick+currentLyricTime then --Is it time to move to the next lyric?
    tick = getTickCount() --If so, reset the tick count for current lyric
    if currentLyric < #lyrics then --Are there any more lyrics left to display?
      currentLyric = currentLyric + 1 --If so, move to next lyric in table
    else
      currentLyric = 0 --Else, we reset everything and stop rendering lyrics
      tick = nil
      removeEventHandler("onClientRender", root, renderLyrics)
      return
    end
  end
  --do dxDrawText here with lyrics[currentLyric].words (the current lyrics that should be displayed)
end

function startLyrics() --Call this to start the lyrics
  currentLyric = 1 --Start lyrics at line 1
  tick = getTickCount() --Get the tick count when current lyric starts
  addEventHandler("onClientRender", root, renderLyrics)
end

I haven't tested, its just a general idea for you to simplify this. What you're doing seems way too over complicated, even without seeing code.

  • Thanks 1
Link to comment
  • Administrators

No problem :)

Also, if I had to guess what the original error means (chunk has too many syntax levels), its because you are doing something similar to this, but with setTimer:

if 1 then
  if 2 then
    if 3 then
      ...
        if 99 then
          if 100 then
            if 101 then
              --chunk has too many syntax levels
            end
          end
        end
      ...
    end
  end
end

not a good practice imo :P

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...