- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
gibbo3771
-
Content Count
3 -
Joined
-
Last visited
Posts posted by gibbo3771
-
-
11 hours ago, payonel said:
Looks like your you've declared `progressUpdate` after your used it, thus passing nil to event.timer for its 2nd argument. Which, btw, isn't allowed, it should error (it requires you pass a function there)
So how come 'clearAndInitProgressBar' is working just fine? I thought it was due to declaring it as not local but changing that seems to have no effect.
10 hours ago, payonel said:btw, if the onTouch callback is made to an event.listern (inside the gui library you are using), which it likely is, then you would see the crash log in /tmp/event.log (it would be crashing because the assert of the 2nd argument is a function and NOT nil)
This piece of code is not crashing, but it should? That's weird.
EDIT: Would also like to start that this:
throwWitherBuildError("Can't build Wither with shield down, are you mad?!?!?")
Is also declared at the end of my file, so technically this should work either right?
-
So I am pretty new to Lua, having only used it very lightly in the past for basic scripts. I am having some issue that hopefully someone can help me with and it can be best described as a "function losing scope". I'll post the code and explain it.
local buildWitherButton = app:addChild(GUI.roundedButton(buttonLeftAnchor, 13, buttonWidth, 7, buttonDefaultColor, bgColor, buttonPressedColor, bgColor, "BUILD WITHER")) buildWitherButton.onTouch = function() if(powerButton.pressed ~= true) then throwWitherBuildError("Can't build Wither with shield down, are you mad?!?!?") return end -- Do wither stuff note.play(80) clearAndInitProgressBar() e = event.timer(1, progressUpdate, 10) -- MC states 10 seconds to build a Wither, so this rough timer will work for now. Call the function every 1 second, for 10 seconds end buildProgressBar = app:addChild(GUI.progressBar(buttonLeftAnchor, 20, buttonWidth, buttonPressedColor, fgColor, textDefaultColor, 0, true, true, "Building Wither : ", "%")) buildProgressBar.hidden = true function clearAndInitProgressBar() buildProgressBar.hidden = false buildProgressBar.value = 0 end local function progressUpdate() buildProgressBar.value = buildProgessBar.value + 50 -- This lines does literally nothing, I can type it wrong and everything, or even assign strings, booleans, tables. It's like the line is completely ignored note.play(75) -- This beeps. wtf is happening above? end
I am using a GUI library, which can be found HERE. I completely lack the knowledge of the language and API to understand what is wrong, it's also impossible to Google :p.
Any ideas?
Event function losing scope?
in Programming
Posted
Ah right, the scope makes sense given that it's a interpreted line by line language. I had a look at the log and right enough, buildProgressBar is nil. So I tried changing the code around, to what you have described so the variable is declared and known, but unassigned. Kinda safely assuming functions are passed as reference, rather than a copy as it would make less sense. I can link the whole program, can't see it helping much!