optionScreen = Core.class(Sprite)
local imgBase = getImgBase()
local font = getFont()
local checkX = 60
local sliderX = 240
local gap = 70
local col = {r=243/255,g=206/255,b=0,a=1}
local soundSlider
local musicSlider
local redSlider
function optionScreen:init()
local screen = Bitmap.new(Texture.new(imgBase.."opt_back.png"))
self:addChild(screen)
screen:setPosition(0,0)
local txtY = 100
local loader = UrlLoader.new("<a href="http://localhost/write.php"" rel="nofollow">http://localhost/write.php"</a><img class="emoji" src="http://forum.gideros.rocks/resources/emoji/wink.png" title=";)" alt=";)" height="20" />
local function onComplete(event)
local myString=event.data -- We got the string here.
local length = string.len(myString)
local i = 1
local echoString = ""
while (i < length+1) do
echoString = echoString .. string.sub(myString,i,i)
i = i+1;
end
print (echoString)
---definition of functions how_many() and getH()
h = how_many(echoString,'\n')
i=1
k=0
local tit = ""
local taken = {}
local theText = {}
while (k < h)
do
theText[k] = TextField.new(nil, "placeholder")
theText[k]:setPosition(150,125+k*50)
theText[k]:setTextColor(0x007B25)
theText[k]:setScaleX(5)
theText[k]:setScaleY(5)
stage:addChild(theText[k])
----here, we found taken[1],taken[2],taken[3]
print (taken[1],taken[2],taken[3])
theText[k]:setText(taken[2])
k = k + 1
end --end of while loop
--]]
index = h
cbox = {}
k = 0
print("h = " .. h)
print("index = " .. index)
while(index>k)
do
print (k)
k = k + 1
end
gonder = {}
--Checkboxes are visible thanks to the below codes
cbox[1] = checkBox.new(checkX, txtY, "Music", col,
function(this)
local state = this:getCheck()
if state then
print("1 checked ")
gonder[1] = true
else
print("1 not checked ")
gonder[1] = false
end
end
)
screen:addChild(cbox[1])
cbox[1]:setCheck(settings.getMusicState())
txtY = txtY + gap
-- Sound On / Off
cbox[2] = checkBox.new(checkX, txtY, "Sound FX", col,
function(this)
local state = this:getCheck()
if state then
print("2 checked")
gonder[2] = true
else
print("2 not checked")
gonder[2] = false
end
end
)
screen:addChild(cbox[2])
cbox[2]:setCheck(settings.getSoundState())
txtY = txtY + gap
-- Autosave On / Off
cbox[3] = checkBox.new(checkX, txtY, "Autosave", col,
function(this)
local state = this:getCheck()
if state then
print("3 checked")
gonder[3] = true
else
print("3 not checked")
gonder[3] = false
end
end
)
screen:addChild(cbox[3])
cbox[3]:setCheck(settings.getAutosaveState())
txtY = txtY + gap
local submitt = Button.new(Bitmap.new(Texture.new(imgBase .. "button_up.png")), Bitmap.new(Texture.new(imgBase .. "button_down.png")))
submitt:setPosition(20, 170)
stage:addChild(submitt)
submitt:addEventListener("click",
function()
local transition = transitions
sceneManager:changeScene("results", 1, transition, easing.outBack, { eventFilter={Event.MOUSE_DOWN} } )
end)
self:removeEventListener("exitEnd", self.onExitEnd)
end --end of function onComplete
--------------------------
local function onError()
print("error")
end
local function onProgress(event)
print("progress: " .. event.bytesLoaded .. " of " .. event.bytesTotal)
end
loader:addEventListener(Event.COMPLETE, onComplete)
loader:addEventListener(Event.ERROR, onError)
loader:addEventListener(Event.PROGRESS, onProgress)
end
-- Let's get rid of all of the elements shall we. This is strictly not required
-- but I thought I'd put it in for completeness
function optionScreen:onExitEnd()
self:removeEventListener("exitEnd", self.onExitEnd)
redSlider:onExitEnd()
greenSlider:onExitEnd()
blueSlider:onExitEnd()
musicSlider:onExitEnd()
soundSlider:onExitEnd()
soundChk:onExitEnd()
musicChk:onExitEnd()
autosaveChk:onExitEnd()
collectgarbage()
end
function optionScreen:adjustRed(this)
col.r = (redSlider:getPos()*2.55)/255
redSlider:setCol({r=col.r,g=0,b=0,a=1})
musicSlider:setCol(col)
soundSlider:setCol(col)
autosaveChk:setCol(col)
soundChk:setCol(col)
musicChk:setCol(col)
end
function optionScreen:adjustGreen(this)
col.g = (greenSlider:getPos()*2.55)/255
greenSlider:setCol({r=0,g=col.g,b=0,a=1})
musicSlider:setCol(col)
soundSlider:setCol(col)
autosaveChk:setCol(col)
soundChk:setCol(col)
musicChk:setCol(col)
end
function optionScreen:adjustBlue(this)
col.b = (blueSlider:getPos()*2.55)/255
blueSlider:setCol({r=0,g=0,b=col.b,a=1})
musicSlider:setCol(col)
soundSlider:setCol(col)
autosaveChk:setCol(col)
soundChk:setCol(col)
musicChk:setCol(col)
end
Comments
If not help, then maybe it's the Code Dependency. Make optionScreen.lua Depends on result.lua
Likes: loves_oi
And what is the possible reason of the error : attempt to index field '?' (a nil value)
stack traceback:
The problem is that self.scenes["result"] is not defined - it's nil. So you are trying to do nil.new(). So error in the result class, or code dependencies.
Code dependency:
In Gideros Studio Right click on optionScreen.lua -> "Code dependencies...". And then check "result.lua"
Likes: loves_oi
Inside of optionScreen.lua
@loves_oi: One of the first things I think you should do is use the up to sate SceneManager.lua that comes with GiderosStudio. I notice from reading the sample above that you are using quite an old version of SceneManager.lua. The reason I know this is that it is one I myself modified a long time ago to add a parameter when I called the scene:init() function.
The new SceneManager.lua in the very least should be used for compatibility reasons.
... Removed as I was wrong ...
*edit*
I see from your recent post that results is actually a scene. Maybe then I was quite correct & you should use the latest SceneManager.lua and pass the results see this link for more info
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
Use SceneManager v1.0.4
+
submitt:addEventListener("click",
function()
local transition = transitions
sceneManager:changeScene("results", 1, transition, easing.outBack, "HELLO, WORLD" )
end)
+
In Gideros Studio Right click on optionScreen.lua -> "Code dependencies...". And then check "result.lua"
"sceneManager:changeScene("results", 1, transition, easing.outBack, "HELLO, WORLD" ) "
should be
"options = Core.class()
options.userData = "Hello, World"
sceneManager:changeScene("results", 1, transition, easing.outBack, options) "
But it is the sceneManager.lua which i am using :
--[[ ....... function SceneManager:init(scenes) self.scenes = scenes self.tweening = false self:addEventListener(Event.ENTER_FRAME, self.onEnterFrame, self) end function SceneManager:changeScene(scene, duration, transition, ease, firsttime) if self.tweening then return end if self.scene1 == nil then self.scene1 = self.scenes[scene].new(firsttime) self:addChild(self.scene1) dispatchEvent(self, "transitionBegin") dispatchEvent(self.scene1, "enterBegin") dispatchEvent(self, "transitionEnd") dispatchEvent(self.scene1, "enterEnd") return end self.duration = duration self.transition = transition self.ease = ease or defaultEase self.scene2 = self.scenes[scene].new(firsttime) self.scene2:setVisible(false) self:addChild(self.scene2) self.time = 0 self.currentTimer = os.timer() self.tweening = true end function SceneManager:onEnterFrame(event) if not self.tweening then return end if self.time == 0 then self.scene2:setVisible(true) dispatchEvent(self, "transitionBegin") dispatchEvent(self.scene1, "exitBegin") dispatchEvent(self.scene2, "enterBegin") end local timer = os.timer() local deltaTime = timer - self.currentTimer self.currentTimer = timer self.time = self.time + deltaTime if self.time > self.duration then self.time = self.duration end local t = (self.duration == 0) and 1 or (self.time / self.duration) self.transition(self.scene1, self.scene2, self.ease(t)) if self.time == self.duration then dispatchEvent(self, "transitionEnd") dispatchEvent(self.scene1, "exitEnd") dispatchEvent(self.scene2, "enterEnd") self:removeChild(self.scene1) self.scene1 = self.scene2 self.scene2 = nil self.tweening = false collectgarbage() end end
Website: http://www.castlegateinteractive.com
https://play.google.com/store/apps/developer?id=Castlegate+Interactive
sceneManager:changeScene("results", 1, SceneManager.flipWithFade, easing.outBack,{x=sendRows[1],xt=gonder[1],y=sendRows[2],yt=gonder[2],z=sendRows[3],zt=gonder[3]})
and in results.lua i want to take the size of the array -last parameter of the funct calling above- ({x=sendRows[1],xt=gonder[1],y=sendRows[2],yt=gonder[2],z=sendRows[3],zt=gonder[3]}) it should return 6 but it returns zero.
I tried calling as this:
sceneManager:changeScene("results", 1, SceneManager.flipWithFade, easing.outBack,{params = {x=sendRows[1],xt=gonder[1],y=sendRows[2],yt=gonder[2],z=sendRows[3],zt=gonder[3]}})
but it didn't give the correct answer ,too. What should i do?
sceneManager:changeScene("results", 1, SceneManager.flipWithFade, easing.outBack,params = {sendRows[1],gonder[1],sendRows[2],gonder[2],sendRows[3],gonder[3]})
it worked.Interesting
How to do this loop with success ?
What should i do?
Thanks in advance
I would *SERIOUSLY* recommend getting a hold of the Beginning Lua Programming book (http://www.amazon.co.uk/Beginning-Lua-Programming-Programmer/dp/0470069171/ref=sr_1_1?ie=UTF8&qid=1347350411&sr=8-1)
and starting with some of the more simple examples, from what I can see your getting seriously mixed up with your closures, accessing upvalues, nested and anonymous functions and a lot of the more powerful (yet complex to use properly) lua concepts.
Start at the beginning - and get a SOLID foundation in the basics of the language before you try the advanced concepts - which in a lot of cases can just as easily be implemented using the basics and at all times remember the KISS principal - the moment the code get's too unwieldy and difficult for you too read then it's time to scale back and consider a simpler implementation, there's nothing worse for breaking your enthusiasm than trying to bang in advanced code that you don't understand, which then doesn't work and you have no way to fix.
You have to remember, most (if not all) of the forum members are NOT professional teachers and will post examples assuming you have a basic understanding or will guide you to places where you can find the knowledge through experimentation and a full understanding of the results that your getting.
One last tip - if your ever in doubt as to what your code is doing or the path through which your code travels, add in LOT's of print() functions, these will allow you to trace the path of the code by comparing the contents of the output window with your program - this is what really allowed me to get an understanding of how lua deals with closures, callbacks, program flow etc.
Hope this helps...
Jon...
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
What about my question Did you find it very easy ? or , does it contain any advance point which i have to know to solve it?
--edit--
I determined the specific problem . But i can't find the solution. I updated the codes above which shows the specific problem