Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Drax on April 03, 2004, 03:15:44 PM

Title: self defined global function
Post by: Drax on April 03, 2004, 03:15:44 PM
hi guys.

Im back again in programming an developing my game. but more about that later.

I need to know how I can define global functions or something like that. I want to make my dialoges in a seperated file, and get the dialoge in the other scripts with the simple line:

Dialoge1();

Is it possible? How? Im trying, but I've found no solution.

Thanx DraX

Title: Re:self defined global function
Post by: Jerrot on April 03, 2004, 03:28:07 PM
Hi DraX !

Dialoge1();
Is it possible? How? Im trying, but I've found no solution.

If you saved your skript with the dialog functions, you can simply include it in your scripts.
for example: #include "scripts\mydialogs.inc"

(There are also global "functions" possible, but I suppose that's not really what you want.
You could e.g. define them as "methods" of the Game object. Or you create your own custom "Dialog" Object and assign the methods to them... you see there are a lot of ways actually ! :) )

 
Title: Re:self defined global function
Post by: Mnemonic on April 03, 2004, 03:37:50 PM
I'm voting for the custom object way.

Create a script file (dialogs.script) containing your funclions declared as methods.

Code: [Select]
method Dialogue1()
{
  ...
}

...


Then create a global object:

Code: [Select]
global Dlg = new Object("dialogs.script");

Then you can call anywhere:

Code: [Select]
Dlg.Dialogue1();

Title: Re:self defined global function
Post by: Drax on April 03, 2004, 08:19:03 PM
Jeah! Thanx, it works fine now.

Now i've finished the gameplay of my planned demo version. It's one bigger quest and the start of the story. (lika a tutorial to learn the gameplay). Now just some interface and sound works to do.

I hope we can release next month the demo.

Greetz DraX    
Title: Re: self defined global function
Post by: raychaser on June 17, 2007, 12:57:14 PM
Hi Mnemonic,

I did exactly what you said above and I put the line

Code: [Select]
global Dlg = new Object("scripts\dialogs.script");
in my game.script file (but I also tried the game_daemon.script file)

the dialogs.script file contains the following:
Code: [Select]
method Dialogue1()
{
Game.Msg("booya");
}


now when I try to run the code "Dlg.Dialogue1();" from scenes\german\scr\window.script I get:  Error@line 12: Method is called for 'Dlg' which is not defined in the log file. I should mention that it works if I run "Dlg.Dialogue1();" from inside the game.script file.

Have I missed something? Why is my global variable not global?
Title: Re: self defined global function
Post by: Mnemonic on June 17, 2007, 01:01:40 PM
You need to declare the global variable in every script where it's going to be used. Just: global Dlg; will do. They variables will share the same global value, but they need to be declared so that the script "knows" about them.