Page 2 of 2

Re: Teaser for a game I'm working on...

Posted: Fri Apr 01, 2011 6:28 am
by Jasoco
I don't suppose that would help me if I need a specific number of buffers but the computer only allows a couple and the pcall still passes the test.

Re: Teaser for a game I'm working on...

Posted: Fri Apr 01, 2011 6:49 am
by Robin
Jasoco wrote:I don't suppose that would help me if I need a specific number of buffers but the computer only allows a couple and the pcall still passes the test.
You could put the creation of framebuffers in a function (in a loop or whatever), and pcall that function. If it fails, you know you don't have enough framebuffers and you need to fall back to something else.

Re: Teaser for a game I'm working on...

Posted: Fri Apr 01, 2011 7:08 am
by Jasoco
Robin wrote:
Jasoco wrote:I don't suppose that would help me if I need a specific number of buffers but the computer only allows a couple and the pcall still passes the test.
You could put the creation of framebuffers in a function (in a loop or whatever), and pcall that function. If it fails, you know you don't have enough framebuffers and you need to fall back to something else.
And if it succeeds, I won't have to call it again, right?

When you say "success, result", does that mean pcall returns true for success and whatever the result of the function is for the function as result?

Edit: Did a little test. I got two different results:

Code: Select all

success, result = pcall(createBuffers)
Returns "true, true"

Code: Select all

success, result = pcall(createBuffers())
Returns "false, attempt to call a boolean value"

What's up with the second one? Do I need to leave the () off? What if I need to pass variables to the function?

Re: Teaser for a game I'm working on...

Posted: Fri Apr 01, 2011 7:18 am
by bartbes
I'm not sure what that createBuffers() function do, but I suspect it returns a boolean value, which pcall then tries to call. Pcall calls for you, so you don't call the function yourself.

Code: Select all

--from
error("Demo")
--to
pcall(error, "Demo")
The first will error, the second will return false, "Demo".

Re: Teaser for a game I'm working on...

Posted: Fri Apr 01, 2011 7:25 am
by Jasoco

Code: Select all

function createBuffers()
  fb = {
    floor = gr.newFramebuffer(math.max(g.w,256), math.max(g.h,256)),
    objects = gr.newFramebuffer(math.max(g.w,256), math.max(g.h,256)),
    osd = gr.newFramebuffer(math.max(g.w,256), math.max(g.h,256)),
    rays = gr.newFramebuffer(math.max(g.w,256), math.max(g.h,256)),
    scroll = gr.newFramebuffer(math.max(g.w,512), math.max(g.h,512))
  }
  for i, f in pairs(fb) do
    f:setFilter("nearest", "nearest")
  end
  return true
end
It doesn't really need to return anything. I just return true for the hell of it.

I want to use as little buffers as possible, but still want to make as much use of them as possible. What would you say a safe number is? I'd like to use at most 8. Right now I have 5. And the first isn't really needed.