Query about Lua programming in DSB
Posted: Mon Jun 18, 2012 9:46 pm
There's something I don't understand about functions and parameters.
I was trying out the code to make a full screen scroll, and this works fine:
But I also noticed I could do it a slightly different way -- when cloning the scroll, don't assign the on_look method to a function, and instead do it like this:
Why do I use exvar[id] in the first example, but exvar[self] in the second? What's the difference? Is one of these methods better than the other? I'm demonstrating that I don't really know what I'm doing and just fiddle around until I get what I want, but I'd like to understand better what's the difference between these two examples.
I was trying out the code to make a full screen scroll, and this works fine:
Code: Select all
function render_large_scroll(self, id, whose_eye)
if (exvar[id] and exvar[id].textID) then
scroll_ID = exvar[id].textID
dsb_fullscreen(show_large_scroll_and_text, EXIT_ON_CLICK, nil, true, false)
end
end
scroll_strings = {
[1] = "Scroll 1 Text",
[2] = "Scroll 2 Text",
[3] = "Scroll 3 Text"
}
obj.scroll_large = clone_arch(obj.scroll, {
name="LARGE SCROLL"
on_look=render_large_scroll
})
function show_large_scroll_and_text(bmp)
dsb_bitmap_textout(bmp, gfx.font_colortest, string.upper(scroll_strings[scroll_ID]), 320, 240, CENTER, colour_white)
end
Code: Select all
function obj.scroll_large:on_look(self, id, whose_eye)
scroll_ID = exvar[self].textID
dsb_fullscreen(show_large_scroll_and_text, EXIT_ON_CLICK, nil, true, false)
end
scroll_strings = {
[1] = "Scroll 1 Text",
[2] = "Scroll 2 Text",
[3] = "Scroll 3 Text"
}
obj.scroll_large = clone_arch(obj.scroll, {
name="LARGE SCROLL"
})
function show_large_scroll_and_text(bmp)
dsb_bitmap_textout(bmp, gfx.font_colortest, string.upper(scroll_strings[scroll_ID]), 320, 240, CENTER, colour_white)
end