Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
What does it mean? — Gideros Forum

What does it mean?

MinstrelMinstrel Member
edited June 2015 in General questions
Hello so i've already had a question answered and that worked fine but now... It's saying this: bad argument #1 to '?' (TextureBase or TextureRegion expected, got no value)
stack traceback:
main.lua:89: in function

This all happen when I press the fire key Z
Sorry I can't provide more info than this, but I really don't know what else to say.

Here is the entire code:
local sound = Sound.new("MakoBeamNCSGiderosCompRemix(-32Db).wav")
local channel = sound:play()
 
application:setBackgroundColor(0x0)
 
width = application:getContentWidth()
 
local username = ""
 
local textInputDialog = TextInputDialog.new("Player1", 
	"Enter Name Player1", username, "Cancel", "Save")
 
backgroundtexture = Texture.new("BGComp.png")
backgroundtexture = Bitmap.new(backgroundtexture)
stage:addChild(backgroundtexture)
backgroundtexture:setAnchorPoint(0.5,0.5)
backgroundtexture:setRotation(90)
backgroundtexture:setPosition(239,160)
backgroundtexture:setScaleX(1.75)
backgroundtexture:setScaleY(1.75)
 
local retrofont = TTFont.new("8-BIT WONDER.TTF", 20, true)
local text = TextField.new(retrofont,username)
text:setPosition(0, 20)
stage:addChild(text)
text:setTextColor(0xfffffff)
text:setScale(1.0)
text:setPosition(10,20)
 
bullet = Texture.new("bullet.png")
bullet = Bitmap.new(bullet)
stage:addChild(bullet)
bullet:setScale(0.3)
bullet:setPosition(0,0)
bullet:setRotation(-90)
 
playership1 = Texture.new("ship.png")
playership1 = Bitmap.new(playership1)
stage:addChild(playership1)
playership1:setAnchorPoint(0.5,0.5)
playership1:setPosition(245,300)
playership1:setScale(1.0)
--playership1:setColorTransform(0.1,0.9,0.3)
 
local function onComplete(e)
	--if e.buttonIndex then
		username = e.text
		text:setText(username)
	--end
end
 
textInputDialog:addEventListener(Event.COMPLETE, onComplete)
textInputDialog:show()
left = false
right = false
 
shipX=width/2
playerDir=0
bDir=0
by= 1
 
bullets = {}
counter  = 1
 
Pool = Core.class(Sprite)
 
function Pool:init()
    self.pool = {}
end
 
function Pool:createObject()
    local b
    --if there is anything in pool take it
    if #self.pool > 0 then
        b = table.remove(self.pool)
    else
        b = Bitmap.new(Texture.new("bullet.png", true))
    end
    stage:addChild(b)
    return b
end
 
function Pool:destroyObject(b)
    b:removeFromParent()
    table.insert(#self.pool, b)
end
 
 
function gameloop(e)
	shipX=shipX + (playerDir* 5)
 
	if shipX<20 then
		shipX = 20
	elseif
		shipX>(width-20) then
		shipX = width - 20
	end	
 
		playership1:setX(shipX)
 
	by=by+(bDir*5)
	bullet:setY(by)
 
end
 
stage:addEventListener(Event.ENTER_FRAME,gameloop)
 
stage:addEventListener(Event.KEY_DOWN,function(e)
	if e.keyCode==KeyCode.LEFT then
		left=true
		playerDir=-1
	elseif e.keyCode==KeyCode.RIGHT then
		right=true
		playerDir=1
	elseif e.keyCode==KeyCode.Z then
 
	print("fire")
	bx,by=playership1:getPosition()
	bullets[counter] = bullet.new()
	stage:addChild(bullets[counter])
	bullets[counter]:setPosition(bx,by)
	bDir=-1
 
	counter = counter+1
 
	end
 
end)
 
stage:addEventListener(Event.KEY_UP,function(e)
	if e.keyCode==KeyCode.LEFT then
		left=false
		if right then
			playerDir=1
		else
			playerDir=0
		end
 
	elseif e.keyCode==KeyCode.RIGHT then
		right=false
		if left then
			playerDir=-1
		else
			playerDir=0
		end
	end
end)
I would use the internet for this but I've no idea how to search this problem so I thought I'd ask the forums.
Thank's for your time. :)

Comments

  • SinisterSoftSinisterSoft Maintainer
    Which line is line 89 in your editor?
    Coder, video game industry veteran (since the '80s, ❤'s assembler), arrested - never convicted hacker (in the '90s), dad of five, he/him (if that even matters!).
    https://deluxepixel.com
  • hgy29hgy29 Maintainer
    Let me guess:
    bullets[counter] = bullet.new()
    Right ?
  • talistalis Guru
    edited June 2015
    @Minstrel just fyi. To make you code post readable, next time highlight your code in your post.

    Here is how to do it:
    Remove the whitespace in below example. :D

    < pre lang="lua">
    here goes your code to highlight...
    < /pre>

    And for your question:
    1-Are you sure the name of the file is bullet.png (in android capital letter matters do not forget)
    2-Check the file format also can it be opened by image viewer.
  • piepie Member
    Hi, knowing which one is line 89 would help :)

    At a first glance, there are some things I would change:

    I can see the Pool class but I can't see it initialized:
    I think it's better if you copy Pool class at the beginning of the file, to be sure you have it available when you create its instance.

    You create a Pool instance with
     bpool = Pool.new()
    (I named it bpool, but you can name it as you like)

    I suppose you don't need to add bpool to stage, since it's just a "repository"

    In Pool:createobject()
    --if there is anything in pool take it
    if #self.pool > 0 then
    b = table.remove(self.pool)
    else
    b = Bitmap.new(Texture.new("bullet.png", true))
     --i think you want to add these:
    b:setScale(0.3)
    b:setPosition(0,0)
    b:setRotation(-90) 
    end
    --stage:addChild(b) remove this line
    return b
    I can't see a bullet class, but you create a new bitmap instance in the pool if the pool is empty, so, instead of bullet.new, ask the pool to create your bullet:
    bullets[counter] = bpool:createobject()

    I didn't test anything, this may contain errors :-\"
  • function gameloop(e)
    is line 89
  • well it was before I added what pie said so now it's: function Pool:destroyObject(b)
  • Btw Talis Do where do I put what you said? Inside the pool function or elsewhere?
  • MinstrelMinstrel Member
    edited June 2015
    Ok now it says for the error:
    main.lua:68: unexpected symbol near '='
    main.lua 68 = a = {{"one", "two"}, 3}
    and is part of this:

    < pre lang="lua">
    a = {{"one", "two"}, 3}
    b = {k = a[1]}
    < /pre>

    Again... Very confused I've done exactly as directed by Talis.
    Thank's for your support :D

  • piepie Member
    edited June 2015 Accepted Answer
    @Ministrel I think that @talis was just making an example on how to highlight code, I can't see how that code could be used in your project :)

    If your error was in #89, and it was "TextureBase or TextureRegion expected, got no value" there is something wrong with some "texture object" you're calling in gameloop.


    I think it's where you setX on playership1.

    so I noticed one thing you're messing up: naming
    playership1 = Texture.new("ship.png")
    playership1 = Bitmap.new(playership1)
    when you state something with the = sign, you're "overwriting" what comes before the sign with anything you have after: in this case playership1.
    You say it is a texture first, then you say that the same object is a Bitmap. This could be a good reason to have that texture related error.

    try with
    playership_txture = Texture.new("ship.png")
    playership1 = Bitmap.new(playership_txture)
    --OR
    --playership1 = Bitmap.new(Texture.new("ship.png")) --which is the same as the two lines above
  • Ok so I was a bit of an idiot thinking that was code... So I did as you recommended the TextureBase error is gone... but now we have this:

    < pre lang="lua">
    a = {{"one", "two"}, 3}
    b = {k = a[1]}
    < /pre>
    [string "property.lua"]:39: bad argument #2 to 'setmetatable' (nil or table expected)
    stack traceback:
    [string "property.lua"]:39: in function 'class'
    main.lua:65: in main chunk

    So I'm going to make a new discussion on that because my question on this discussion has been answered.
    Once again, Thank you for your continuing help and support.
  • Ok so I've done what you said and I can now start the game (WooHoo)
    So now were back to my first problem... It's giving me an error when I press the fire key Z.
    But do not fear it's a different one so we're definitely getting there.

    The Error is:
    main.lua:122: attempt to call method 'createobject' (a nil value)
    stack traceback:
    	main.lua:122: in function <main.lua:111>
    and line 122 is:
    bullets[counter] = bpool:createobject()
    Once again thank you for your continued support help and time and I know we're getting there, I can feel it!
  • @minstrel it was an example how to highlight your code on this forum. It is nothing related with your question :D

    So as a result do not add this code that i posted no where in your main.lu please . It was just an example.

    Note: I edited my post and deleted the code sample :D
  • Ok thanks. No worries about it though and thanks for the tip.
Sign In or Register to comment.