Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
getTextureRegion question — Gideros Forum

getTextureRegion question

saeyssaeys Member
edited May 2015 in General questions
Sorry for continuous questions here, but I think (hope) this is (another) small one:

I keep getting the error "TextureBase or TextureRegion expected, got nil" at the getTextureRegion line:
	puffs = TexturePack.new("texturepacks/puff.txt", "texturepacks/puff.png", true)
	for i = 0, 3 do
		puff[i] = Bitmap.new(puffs:getTextureRegion("puff0"..i..".png"))
	end
Clearly something that I'm missing here, just can't find it. Anyone?

Comments

  • hgy29hgy29 Maintainer
    Are your textures in your texture packs actually named pbuff00.png, pbuff01.png and so on ?
  • SinisterSoftSinisterSoft Maintainer
    edited May 2015
    Plus the case is important - make sure the original filenames are lowercase too.

    And also check to see if puffs is nil...
    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
  • saeyssaeys Member
    Actually, they are named puff01.png up to 04, so the for statement should have been från 1 to 4 instead of 0 to 3.

    Still the same error, though. Output says "puffs" is a table, is that right? File names are re-re-rechecked, all lower case.
  • SinisterSoftSinisterSoft Maintainer
    yes puffs should be a table.

    make it no you have local texture=puffs:getTextureregion... then check texture for being nil. that way you can isolate the problem to either getting the region or creating the bitmap.

    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
  • saeyssaeys Member
    You mean like this?
    puff = Bitmap.new(puffs:getTextureRegion("puff01.png"))
    Well, the error dissapears. So maybe there is an issue with the for loop and its syntax that I don't see or understand. I've copied and compared with several examples in other posts in this forum. And I really would like to use a for loop - more efficient and resource saving.

    Btw, how do I get the nice coloured code format in posts? (instead of just yellow)
  • hgvyas123hgvyas123 Guru
    Accepted Answer
    as your name are like puff01.png, puff02.png,...

    so you need to start your for loop from 1

    try
    puffs = TexturePack.new("texturepacks/puff.txt", "texturepacks/puff.png", true)
    	for i = 1, 4 do
    print("puff0"..i..".png")
    		puff[i] = Bitmap.new(puffs:getTextureRegion("puff0"..i..".png"))
    	end
    also now you can compare your image name with actual image name as they will get print in console
  • saeyssaeys Member
    I got it, thanks @hgvyas123. The "for 0, 3 do" kept hanging around, naturally didn't work as the first file was numbered 01. Also, got confused about the other error messages I got as I hadn't defined the table with
    local puff = {}
    before the for loop. Going on with my life... ;-)
  • SinisterSoftSinisterSoft Maintainer
    lol, I thought you had fixed this when you spotted 'Actually, they are named puff01.png up to 04, so the for statement should have been från 1 to 4 instead of 0 to 3' was wrong above! ;)
    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
  • saeyssaeys Member
    Well, I had, but then I got another error at the same line because "puff" wasn't defined, so I thought the two errors generally was connected to each other somehow. :-)

    And again, what tag can I use to display nicely coloured code in this forum? < pre lang = " something? " >
  • hgy29hgy29 Maintainer
    yes, lang="lua" :)
  • saeyssaeys Member
    @hgy29 For me, lang="lua" makes
    a yellow square
    with black text. A previuos post says something about a source view setting, but I can't find that anywhere. Never mind, not that important. :-)
  • piepie Member
    @saeys

    just only one space in string between pre and lang
    --<pre lang="lua">  //<pre_SPACE_lang="lua"> 
    local test = test.new()
    here I have another space between = and "lua"> (can't write it, it's being interpreted)
    local test = test.new()
    :)
  • saeyssaeys Member
    Got it, thanks!
Sign In or Register to comment.