Light Style© by Fisana

Jump to content


Where to add my global scripts?

  • Please log in to reply
2 replies to this topic

#1 aleReimondo



  • Community Members
  • 5 posts

Posted 07 February 2012 - 01:39 PM


I want to add some custom modifications and extensions to String and other
base methods (changes at javascript level).
That changes must be visible at any page of the game and while playing the game.
Where is the place to add the expression to load my script files ?

thanks in advance,
p.d. I have tried to inject scripts in a new page, but when loading another
page in the game from main menu, the methods fail execution
with error (shown in console)
ERROR: Javascript error: s8/8AD.js line 436
TypeError: "hello".printMe is not e afunction
ERROR: GUI: Error executing script s8/8AD.js: Scripting_LoadFile_EvalErrors
When I query using console
typeof "Hello".printMe it is returned "function"
and it is correctly defined.
  • 0

#2 Ykkrosh


    Primus Pilus

  • WFG Programming Team
  • 4,928 posts

Posted 07 February 2012 - 07:39 PM

Changing the standard global objects is generally a very bad idea in JS, so don't do that :). It's particularly problematic in our GUI system since we have a separate global scope per GUI page, with some magic to resolve properties on the real global object when necessary, and SpiderMonkey's JIT optimisations interact in complex ways with global objects too, so it gets confusing and fragile. Just use a normal function instead.
  • 0
Philip Taylor [aka Ykkrosh]

Wildfire Games Programmer
Contact me:

#3 aleReimondo



  • Community Members
  • 5 posts

Posted 07 February 2012 - 09:41 PM

I use normal functions, all normal functions and delegation; and all works w/o any problem on V8, IE, etc (without surprises, nor limitations and also fast).
I see that design can impose us limitations to "protect execution success" and can be not safe/possible to run my frameworks here.
IMO the safety at expense of "each page/stage a world" is a severe limit for scripting a game.

Is there a simple way to load js code when booting top context? (at root)
I am asking for a place to patch the engine to load my file
into javascript at boot... as it was part of core js impl.

thanks for your time,

p.d.: I am too old to stop when someone say "dontīdo that". So if it is possible, I will try;
if it is not possible (at js level), it is also ok; I can try to run in one page.
  • 0