Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Slav on March 09, 2011, 08:17:38 PM

Title: .window file with multiple scripts - disambiguation
Post by: Slav on March 09, 2011, 08:17:38 PM
Hello.
I write Flash (ActionScript3) bind for WME and faced the puzzle:
.window file contains two scripts:
Quote
SCRIPT = dialog.script
SCRIPT = mini_game.script
and both of them contain "init()" function - which one must be called when window's function init() is called? May be both of them?
Title: Re: .window file with multiple scripts - disambiguation
Post by: Mnemonic on March 09, 2011, 08:42:34 PM
I don't understand the question. Those are your custom functions so you must know if you want to call them and when.
Title: Re: .window file with multiple scripts - disambiguation
Post by: Slav on March 09, 2011, 09:41:39 PM
Sorry for confusing.
I know which function must be called - but my Flash port does not. Which one will be called within original WME engine? By which rules WME chooses a script to call it's function? Searches from end to start (call last one) (so it will looks like "inheritance")?
Thank you.

P.S. I write Flash port for already released C++ (original WME) game - so it is possible to hack .script file in such a way that needed function will be called (other one is just empty) but there are tons of .script and .window files - I will not be able to edit all of them (and, anyway, Flash port must work fine).
Title: Re: .window file with multiple scripts - disambiguation
Post by: Mnemonic on March 09, 2011, 09:50:08 PM
If it's a local function (declared with "function") it can only be called from within the script itself, so it's never ambiguous. If it's a public function (declared with "method") and called from the outside, the one from the last script is called.

In your case, if both scripts contain a method called "init", and you call window.init(), the method from mini_game.scritpt will be called. That way you can override methods by adding a new script on top of existing ones.
Title: Re: .window file with multiple scripts - disambiguation
Post by: Slav on March 09, 2011, 09:52:48 PM
It's "method".
Just like I thought.
Thank you!
Title: Re: .window file with multiple scripts - disambiguation
Post by: Jose on April 25, 2011, 02:16:03 AM
So "method" and "function" have nothing to do with returning values or not but with the scope?

I thought that the methods never return any value and function do. But reading this thread I realize that the difference between both is that functions are local to the script were they're defined and methods are public, am I right?
Title: Re: .window file with multiple scripts - disambiguation
Post by: Mnemonic on April 25, 2011, 08:17:16 AM
Yes, that's right.
Title: Re: .window file with multiple scripts - disambiguation
Post by: Jose on April 25, 2011, 04:55:54 PM
Thanks Mnemonic