Set character to new scene (Lua)

  • #1, by darren-beckettSaturday, 23. January 2016, 12:34 7 years ago
    I'm trying to make a character change scene in Lua, but this doesn't seem to work?
    getObject("Characters[Receptionist].CharacterScene"):setValue(VCharacterScene, game:getLink("Game.GameCurrentCharacter.CharacterScene"))

    Great Poster

    383 Posts


  • #2, by SimonSSaturday, 23. January 2016, 13:03 7 years ago
    Try:
    Characters["Receptionist"].Scene = game.CurrentCharacter.Scene
    

    Thread Captain

    1552 Posts

  • #3, by afrlmeSaturday, 23. January 2016, 13:55 7 years ago
    Thing was that you didn't need to declare .CharacterScene in the getObject function as the setValue function would have taken care of that.

    Simon's shorthand method is definitely the way to go. wink

    Imperator

    7178 Posts

  • #4, by darren-beckettSaturday, 23. January 2016, 14:29 7 years ago
    This works:
    mChar = getObject("Characters[Receptionist]")
    mChar.CharacterScene = game.GameCurrentCharacter.CharacterScene

    Thanks

    Great Poster

    383 Posts

  • #5, by afrlmeSaturday, 23. January 2016, 14:55 7 years ago
    Question: why did create variables? It seems like unnecessary work to me.

    Simon' one line would have worked. Speaking of faster workflow methods, you could actually create a Lua function to reduce the amount of characters / code / lines you need to type.


    function...
    function char2scn(c, s)
     -- + fallback + --
     if c == nil then c = game.CurrentCharacter:getName() end
     if s == nil then s = game.CurrentScene:getName() end
     -- + set character to scene + --
     Characters[c].Scene = Scenes[s]
    end
    

    usage...
    char2scn("Tom", "Kitchen") -- set character Tom to Kitchen scene
    ...
    char2scn(nil, "Kitchen") -- set active character to Kitchen scene
    ...
    char2scn("Tom") -- set character Tom to currently displayed scene
    

    ... I think you get the idea. smile

    Imperator

    7178 Posts

  • #6, by darren-beckettSaturday, 23. January 2016, 15:45 7 years ago
    Android cannot access the Characters[] table directly.

    Great Poster

    383 Posts

  • #7, by afrlmeSaturday, 23. January 2016, 15:51 7 years ago
    Oh. Didn't know that. I would have thought that both the getObject & shorthand Lua access / update methods would be compatible across all the available platforms. Well, you could replace the Characters bit in the function I wrote with the getObject method instead.

    Are there any other shorthand tables that you've come across that can't be accessed directly on Android either?

    Imperator

    7178 Posts

  • #8, by darren-beckettSaturday, 23. January 2016, 16:03 7 years ago
    These do not work: ActiveAnimations[], Values[], Interfaces[], Characters[]

    Note: I believe it may be all of them.

    Great Poster

    383 Posts

  • #9, by afrlmeSaturday, 23. January 2016, 17:09 7 years ago
    Ah... I guess it doesn't like shorthand in general. Strange, very strange.

    Imperator

    7178 Posts