Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
TNT Virtual Pad for Gideros — Gideros Forum

TNT Virtual Pad for Gideros

AxlFlameAxlFlame Member
edited July 2014 in Game & application design
Hey, guys!

So, in my current project, I started using the TNT Virtual Pad for Gideros (which is awesome, btw). The problem is, when I try to implement it on my existing project and use it, it gives me this error:

"attempt to index field 'data' (a nil value)"

I have both tntvpad32 and tntvpad64 in my project.

Can someone help me with this? I tried contacting the creator via his site, but with no success so far..

Here's the code from my minigame class: (the pad is only implemented on one of the project's minigames):
	-- setup Virtual Pad
	vPad = CTNTVirtualPad.new(stage, "images/Minigames/CEO/M1/Controle/tntskinpad",  PAD.STICK_SINGLE, PAD.BUTTONS_ONE, 20,2)
 
	vPad:setTextures(PAD.COMPO_BUTTON1, "buttona.png","buttonb.png")
	vPad:setJoyStyle(PAD.COMPO_LEFTPAD, PAD.STYLE_CLASSIC)
	vPad:setJoyAsAnalog(PAD.COMPO_LEFTPAD, false)
	vPad:setJoyAsAnalog(PAD.COMPO_RIGHTPAD, true)
	--vPad:setICade(false)
	vPad:start()
 
	function leftJoy(e)
		if e.data.power > 0.2 then
			player:move(e.data.angle, (e.data.power*150)*e.data.deltaTime)
		end
	end
 
	function rightJoy(e)
		if e.data.selected then
			player:setRotation(math.deg(e.data.angle*.786)+90)
		end
	end
 
	function fire(e)
		if e.data.state == PAD.STATE_BEGIN then
			local fire = CLASS_fire.new(player.xPos, player.yPos-20)
			stage:addChild(fire)
		end
	end
 
	function protection(event)
		if event.data.state == PAD.STATE_DOWN then
			player.protection:setVisible(true)
		else
			player.protection:setVisible(false)
		end
	end
 
	vPad:addEventListener(PAD.LEFTPAD_EVENT, leftJoy, self)
	vPad:addEventListener(PAD.BUTTON1_EVENT, protection, self)
	vPad:addEventListener(PAD.BUTTON2_EVENT, protection, self)

Comments

  • edited July 2014
    Hi @AxlFlame, try this (do not include self param)
    	vPad:addEventListener(PAD.LEFTPAD_EVENT, leftJoy)
    Coming soon
    +1 -1 (+4 / -0 )Share on Facebook
  • ar2rsawseenar2rsawseen Maintainer
    @vitalitymobile is right, just to elaborate, when you do
    vPad:addEventListener(PAD.LEFTPAD_EVENT, leftJoy)
    it translates to
    function leftJoy(e)
    	if e.data.power > 0.2 then
    		player:move(e.data.angle, (e.data.power*150)*e.data.deltaTime)
    	end
    end
    But when you do
    vPad:addEventListener(PAD.LEFTPAD_EVENT, leftJoy, self)
    it translates to
    function leftJoy(self, e)
    	if e.data.power > 0.2 then
    		player:move(e.data.angle, (e.data.power*150)*e.data.deltaTime)
    	end
    end
    So basically you are naming self (which is passed as 1st argument) as e and try to access data property, which does not exist ;)
    +1 -1 (+3 / -0 )Share on Facebook
  • Oh.. I get it now!

    Thanks @vitalitymobile for the answer and @ar2rsawseen for the explanation!
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.