Game Development Community

Help with script callbacks

by Danner Jones · in Torque Game Engine · 02/04/2004 (8:15 pm) · 6 replies

Can someone help me understand why I need to have some callbacks (a function in script called by the engine) be inside a package?

In the Tiny Demo I had to put the function "function MainMenuGui::onWake()..." inside a package for it to get called. The same goes for the "resetCanvas" function. When I left them declared in script, outside a package, the engine would never call into them. The console would report " (0): Unable to find function resetCanvas".

Is that the way that Con::executef works, or is it something else that I've done (or not done)?

As far as I could tell from looking at the engine code, it might be because every function MUST be in a namespace? Would that imply that a package creates a namespace? I couldn't find any info on that, if it's true.

-Nerseus

edit: fixed url

#1
02/05/2004 (10:17 am)
That is very strange. Is MainMenuGui defined in a package? That might be why it's not working.
#2
02/05/2004 (10:29 am)
Umm.. you're abusing the package function terribly in the TinyDemo.

Basically you're using it just to use it, but it isn't serving a purpose.

You need to do something with the demo that can show the difference between using the package and not using it.
#3
02/05/2004 (12:48 pm)
I'm confused by both of your responses...
@Ben: MainMenuGui IS defined in a package to get it working. Without the package, just declared "globally", it never gets called. My question is *why*...

@LabRat: I'm only "abusing" the package because the function wouldn't get called unless it was *inside* a package. I would have preferred keeping the functions "global" but they never got called.

-Nerseus
#4
02/05/2004 (1:38 pm)
Below is a fixed main.cs of your tinydemo, It doesn't have all the comments you had in your example. But it should give you an idea on what you need to do to get things working.

Fixed Main.cs
#5
02/05/2004 (2:09 pm)
Thanks LabRat. Seems I needed the call to "setNetPort(0);" as it did the trick. Scanning the engine, I can't see what that call does that NOT calling it might prevent some script functions from being called. I'll be looking into it to find out.

-Ner
#6
02/05/2004 (3:24 pm)
It sets the local IPX port