Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
Changing some code - Gideros Forum

Changing some code

tytadastytadas Member
edited December 2016 in General questions
Hello everyone. I have small question to ask, nothing special just about implementing another project to my main game project. I'm using ar2rsawseen's Multi Slider code and I found out it works with scene manager. I implemented it into my project and the multi slider code works great, but.. I imported the slider code into my onEnterEnd function and other buttons lost the functionality with the error:
classes/scenemanager.lua:287: attempt to index field '?' (a nil value)
stack traceback:
	classes/scenemanager.lua:287: in function 'changeScene'
	scenes/gamesc.lua:41: in function
I can see that slider uses sceneManager and a Sprite and I do believe I have to change the sceneManager code to something else so the other buttons could work. I tried addEventListener but none of my codes worked well.

I don't need full code or such, I'm here to ask some tips about what should I use to manage the slider and other buttons to work in the same time.

Thanks

Comments

  • piepie Member
    edited December 2016
    Hi, please assume that who reads here doesn't know your project, every detail you can provide could be useful.
    I think that the issue is in your code: you should not change scenemanager unless you know why :)
    output says that everything started at
    scenes/gamesc.lua:41

    What do you have here? You need to trackback from there, until you find the wrong parameter sent to scenemanager:changescene (...).
  • tytadastytadas Member
    edited December 2016
    Ty pie for the answer!

    This is the gamesc.lua file. The line 41 is: "sceneManager:changeScene("storesc", conf.transitionTime, conf.transition, conf.easing)" .
    gamesc = Core.class(Sprite)
     
    function gamesc:init()
     
     
    local background = Bitmap.new(Texture.new("images/background.png", true))
    	background:setAnchorPoint(0.5,0.5)
    	self:addChild(background)
    	background:setPosition(conf.width/2, conf.height/2)
    	self:addEventListener("enterEnd", self.onEnterEnd, self)
     
    end
     
    function gamesc:onEnterEnd()
     
    	local backbutton = Bitmap.new(Texture.new("images/backbutton.png", true))
    	backbutton:setAnchorPoint(0.5,0.5)
    	backbutton:setPosition((conf.height - backbutton:getHeight())/2 - 290, conf.width - 410)
    	self:addChild(backbutton)
     
    		backbutton:addEventListener(Event.MOUSE_DOWN, function(e)
    			if backbutton:hitTestPoint(e.x,e.y,true) then
    			gamesc = nil 
    			collectgarbage()
    			sceneManager:changeScene("mainsc", conf.transitionTime, conf.transition, conf.easing)
    			end
    			end)
     
     
     
    	local storebutton = Bitmap.new(Texture.new("images/storebutton.png", true))
    	storebutton:setAnchorPoint(0.5,0.5)
    	storebutton:setPosition((conf.height - backbutton:getHeight())/2 - 270, conf.width - 280)
    	self:addChild(storebutton)
     
    		storebutton:addEventListener(Event.MOUSE_DOWN, function(e)
    		if storebutton:hitTestPoint(e.x,e.y,true) then
    		gamesc = nil
    		collectgarbage()
    		sceneManager:changeScene("storesc", conf.transitionTime, conf.transition, conf.easing)
    		end
    		end)
     
     
    	local boostButton = Bitmap.new(Texture.new("images/boostbutton.png", true))
    	boostButton:setAnchorPoint(0.5,0.5)
    	boostButton:setPosition((conf.height - boostButton:getHeight())/2 - 100, conf.width - 280)
    	self:addChild(boostButton)
     
    		boostButton:addEventListener(Event.MOUSE_DOWN, function(e)
    		if boostButton:hitTestPoint(e.x,e.y,true) then
    		gamesc = nil
    		collectgarbage()
    		sceneManager:changeScene("storesc", conf.transitionTime, conf.transition, conf.easing)
    		end
    		end)
     
    	local profilebutton = Bitmap.new(Texture.new("images/profilebutton.png", true))
    	profilebutton:setAnchorPoint(0.5,0.5)
    	profilebutton:setPosition((conf.height - profilebutton:getHeight())/2 + 50, conf.width - 280)
    	self:addChild(profilebutton)
     
    		profilebutton:addEventListener(Event.MOUSE_DOWN, function(e)
    		if profilebutton:hitTestPoint(e.x,e.y,true) then
    		gamesc = nil
    		collectgarbage()
    		sceneManager:changeScene("storesc", conf.transitionTime, conf.transition, conf.easing)
    		end
    		end)
     
     
    	--[[local earthselect = Bitmap.new(Texture.new("planetsm/earthplanet.png", true))
    	earthselect:setPosition((conf.height - earthselect:getHeight())/2 - 50, conf.width - 35)
    	earthselect:setAnchorPoint(0.5,0.5)
    	self:addChild(earthselect)
     
    	earthselect:addEventListener(Event.MOUSE_DOWN, function(e)
    		if earthselect:hitTestPoint(e.x,e.y,true) then
    		gamesc = nil 
    		collectgarbage() 
    		sceneManager:changeScene("gamesc", conf.transitionTime, conf.transition, conf.easing)
    		end
    		end)
    		--]]
    		local crates = {
    	{"planetsm/mercuryplanet.png", "planetsm/marsplanet.png", "planetsm/earthplanet.png", "planetsm/saturnplanet.png", "planetsm/uranusplanet.png", "planetsm/sunplanet.png"},
    }
     
    local scenes = {}
     
    currentScene = 1
     
    for i in pairs(crates) do
    	local scene = Core.class(Sprite)
    	function scene:init()
    		AceSlide.init({parent = self})
    		for j in pairs(crates[i]) do
    			AceSlide.add(Bitmap.new(Texture.new(crates[i][j], true)))
    		end
    		AceSlide.show()
     
     
    		local leftButton = Button.new(Bitmap.new(Texture.new("images/arrowleft.png")), Bitmap.new(Texture.new("images/arrowleft.png")))
    		leftButton:setPosition((application:getContentWidth()-leftButton:getWidth())/5, (application:getContentHeight()/2)-(leftButton:getHeight()/2))
    		self:addChild(leftButton)
    		leftButton:addEventListener("click", 
    			function()	
    				AceSlide.prevItem()
    			end
    		)
     
    		local rightButton = Button.new(Bitmap.new(Texture.new("images/arrowright.png")), Bitmap.new(Texture.new("images/arrowright.png")))
    		rightButton:setPosition(((application:getContentWidth()-rightButton:getWidth())/5)*4, (application:getContentHeight()/2)-(rightButton:getHeight()/2))
    		self:addChild(rightButton)
    		rightButton:addEventListener("click", 
    			function()	
    				AceSlide.nextItem()
    			end
    		)
     
     
     
    		local function onMouseDown(self, event)
    			if self:hitTestPoint(event.x, event.y) then
    				self.isFocus = true
    				self.startY = event.y
    				self.initY = self:getY()
    				self.y0 = event.y
     
    				event:stopPropagation()
    			end
    		end
     
    		local function onMouseMove(self, event)
    			if self.isFocus then
    				local dy = event.y - self.y0
     
    				self:setY(self:getY() + dy)
     
    				self.y0 = event.y
     
    				event:stopPropagation()
    			end
    		end
     
    		local function onMouseUp(self, event)
    			if self.isFocus then
    				local back = false
    				if self.startY < self.y0 - 10 then
    					if currentScene > 1 then
    						currentScene = currentScene - 1
    						sceneManager:changeScene("scene"..currentScene, 1, SceneManager.moveFromTop, easing.outBack)
    					else
    						back = true
    					end
    				elseif self.startY > self.y0 + 10 then
    					if currentScene < #crates then
    						currentScene = currentScene + 1
    						sceneManager:changeScene("scene"..currentScene, 1, SceneManager.moveFromBottom, easing.outBack)
    					else
    						back = true
    					end
    				else
    					back = true
    				end
    				if back then
    					GTween.new(self, 1, {y = self.initY})
    				end
    				self.isFocus = false
    				event:stopPropagation()
    			end
    		end
     
    		self:addEventListener(Event.MOUSE_DOWN, onMouseDown, self)
    		self:addEventListener(Event.MOUSE_MOVE, onMouseMove, self)
    		self:addEventListener(Event.MOUSE_UP, onMouseUp, self)
    	end
    	scenes["scene"..i] = scene
    end
     
     
    sceneManager = SceneManager.new(scenes)
     
    self:addChild(sceneManager)
     
    sceneManager:changeScene("scene"..currentScene, 1, SceneManager.flipWithFade, easing.outBack)
     
     
     
     
    end
  • piepie Member
    Accepted Answer
    Are you defining "storesc" in scenes? can you read conf table?
    without the full project is hard for me to debug. :)

    how many SceneManager.new(scenes) do you have in your project?
    I see you are creating one global sceneManager object at the end of gamesc.lua, but from your object name gamesc I suppose you already created one, in which you loaded this scene. Am I right?
    Maybe you are overwriting the "old" sceneManager, and you're missing the previously defined scenes (where you should have defined "storesc")

    Likes: tytadas

    +1 -1 (+1 / -0 ) Share on Facebook
  • Thanks haha! Your clearly explanation at first was confusing me, but haha I made it out!
Sign In or Register to comment.