Graphics

 View Only
  • 1.  Global Methods... but not variables.

    Posted 01-24-2017 22:51
    So I see the new global method section, and that's awesome for not having to duplicate a lot of code, but it seems there's no way to do global variables.

    I get that the problem is there can be multiple instances of a scene, but if that didn't matter to me, is there a way to have global variables?

    We have a very cools system running giving real time stats from a game, but for each of ten players, it requires 15 api calls (for six objects associated with the player, where we read a value that is set by datalinq, get the scene object, then apply a texture to it based on the value).

    Performance is over %200.

    If we could set an array of those objects somewhere, we'd only need 5 API calls to set the texture, a total of 50 instead of 150 overall. In this same function, when it was only 3 per player (the first object we set), we were safely in real time, so I think 5 could work.


  • 2.  RE: Global Methods... but not variables.

    Posted 01-25-2017 00:20

    As the global scripts are compiled and run in individual compartments, per scene, these can’t communicate with each other.
    If you want to share objects / variables, you can however use the xpGlobal object:

    To set a value:
    _Global.SetValue(“variableName”, Value)

    To retrieve it:
    Value = _Global.GetValue(“variableName”)

    To delete the variable/object:
    _Global.DeleteValue(“variableName”)

    And finally, to check if a variable/object exists in the global space:
    _Global.KeyExists(“variableName”)

    The values being stored are of type variant and can represent a whole host of things, simple values up to complete objects. You should not store XPression objects inside of these however as the internal reference counting will become invalidated and you can lead to a memory leak.


    #XPression


  • 3.  RE: Global Methods... but not variables.

    Posted 01-25-2017 13:04
    Thanks, will try that - I was hoping to avoid calls, but think this will still be significantly faster than the API calls to get all the objects every frame.

    BTW, I was in Ottawa last month and got a tour of the facility - walked by your office, but didn't want to bother you. Thanks for all your help.
    #XPression


  • 4.  RE: Global Methods... but not variables.

    Posted 01-25-2017 13:15
    If we delete the objects in the OnOffline script, would that avoid the problem?
    #XPression


  • 5.  RE: Global Methods... but not variables.

    Posted 01-25-2017 13:40
    Are you trying to set the value of text objects? The most efficient way to do this is to use xpScene.SetObjectPropertyString("ObjectName","Text", "The value you want to set")
    This call avoids getting a handle to the object and simply applies the string to the text property.

    You can use this same call to apply a pre-existing material to an object as well.
    i.e. xpScene.SetObjectPropertyString("ObjectName", "Material", "TheMaterialName")

    As well this can access (most) other properties (the same ones visual logic can set) of the objects.
    #XPression


  • 6.  RE: Global Methods... but not variables.

    Posted 01-25-2017 17:10
    Thanks... we did a lot better by using a bunch of materials with the setobjectproperty method instead of setVolatileTexture method, safely in real time now (and it makes a lot of sense).

    #XPression