Run script on startup without using game.inituserinterface?

Hi to all adventure fans. ;-)

Do any of you have an idea like me at development time, so if I have developed my own tab in the game menu, can add a script to run when starting the game without having to use the script game.inituserinterface? To my knowledge, I can only execute the script language during runtime. That's why I've ruled out that option so far.


Not sure I get what you mean, but you can have an initialisation script run on any object at start-up. Activate on the Features tab to see it.


I think the question was "Is it possible for my library to put code into the inituserinterface script?"

(This is an extension of something that bugs me about the library system in general; the various scripts on an object or on the game can be replaced but not modified. Writing more complex libraries would be a lot easier if the attribute passed to do() could be either a script, or a list of scripts. Then it would be fairly easy to write a function which adds a script to a certain object, without having to worry about other libraries using the same event)


Yes, it's difficult to explain. For example, I use the game.inituserinterface for the library "StyleSheet" (To see here) to be able to execute the settings at game start. However, if changes already made by the user had to be made in the script, the user must insert the function call himself.


I do think that it would be very useful to have a couple of extra functions in core:

<function name="AddScriptAttribute" parameters="object, attribute, script">
  if (not HasAttribute(object, attribute)) {
    set (object, attribute, script)
  }
  else {
    value = GetAttribute (object, attribute)
    if (not Equal(value, script)) {
      if (TypeOf(value) = "list") {
        if (not ListContains(value, script)) {
          list add (value, script)
        }
      }
      else {
        list = NewList()
        if (EndsWith(TypeOf(value), "list")) {
          foreach (i, value) {
            list add (list, i)
          }
        }
        else {
          list add (list, value)
        }
        if (not ListContains(list, script)) {
          list add (list, script)
        }
        set (object, attribute, list)
      }
    }
  }
</function>

<function name="RunScriptAttribute" parameters="object, attribute, params">
  if (HasAttribute(object, attribute)) {
    attr = GetAttribute(object, attribute)
    if (TypeOf(attr) = "script") {
      do (object, attribute, params)
    }
    else if (TypeOf(attr) = "list") {
      params = params
      dictionary add (params, "this", object)
      foreach (script, attr) {
        if (TypeOf(script) = "script") {
          invoke (script, params)
        }
      }
    }
  }
</function>

If the core scripts used a function like this RunScriptAttribute to call things like inituserinterface, then a library could simply call AddScriptAttribute, without having to worry if another library also needs to add interface initialisation stuff. Like in Javascript's event handlers, you could have a list of scripts to run without needing to worry. It's still possible to use script lists like this (storing the list under a different name, and setting a script that loops over the list), but it's a lot less stable.

I'd really like to see do() handle lists of scripts in this way natively, or a script like RunScriptAttribute wrapped around it. But really, that's only useful if you know that all the libraries you're using will understand it.


Log in to post a reply.

Support

Forums