Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
index '__userdata' cannot be found — Gideros Forum

index '__userdata' cannot be found

mt206mt206 Member
edited July 2012 in General questions
Hi all,

I am running in to an issue that is stumping me and I was hoping for some tips to point me in the right direction.

The problem I am facing is how to add my character sprite and associated physics body when the Player:init() method is called. I am running in to an error: "index '__userdata' cannot be found" when I try to add the player to the Player object:
self:addChild(player)
Just for some background, I am using SceneManager, and I am adding the Player to my Game scene like so:
self.player = Player:new(self.world, centerX, centerY, 5, levelSpeed, 0, "gfx/pig.png")
self:addChild(self.player)
Here is my Player class where the problem resides:
Player = Core.class(Sprite)
 
-- b2World: the box2d World object to add the player body to
function Player:init(self, b2World, xVal, yVal, lives, speed, burnRadius, spriteLocation)
 
	self.lives = lives
	self.speed = speed
	self.burnRadius = burnRadius
 
	local player = Bitmap.new(Texture.new(spriteLocation))
	player:setAnchorPoint(0.5,0.5)
	player:setPosition(xVal, yVal)
 
        local radius = player:getWidth()/2
 
        local body = b2World:createBody{type = b2.DYNAMIC_BODY}
	body:setPosition(player:getX(),player:getY())
	body:setAngle(player:getRotation() * math.pi/180)
 
        local circle = b2.CircleShape.new(0,0,radius)
	local fixture = body:createFixture{
		shape = circle,
		density = 1.0,
		friction = 0.1,
		restitution = 0.8
	}
 
	player.body = body
	player.body.type = "player"
 
        --THE PROBLEM LINE BELOW-----------------------------
	self:addChild(player)
end
Tagged:

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited July 2012
    Well, this kind happens when you try to add none Gideros object to Sprite hierarchy, like table or something.
    I looked at your code, and all I saw is the problem with the constructor, you initiate class like this:
    self.player = Player.new(self.world, centerX, centerY, 5, levelSpeed, 0, "gfx/pig.png")
    there should be a dot between Player and new, not a colon, which could be related to the problem

    Likes: mt206

    +1 -1 (+1 / -0 )Share on Facebook
  • mt206mt206 Member
    Yahtzee! To think I spent an hour and a half trying to figure out what was wrong when the only problem was a colon instead of a period.

    This had the nice side effect of fixing a peculiarity in my Player:init() call. I had to add 'self' as one of the arguments passed to the init() method which I didn't understand the need for (since the colon means it is self referencing anyways). I was able to remove that after fixing my error.

    I am really liking Gideros (not so much a fan of Lua but that's another story) and it's good to see that there is a community supporting it.

    Thanks for your help!

    Likes: gorkem

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.