Set character to new scene (Lua)

  • #1, by darren-beckettSaturday, 23. January 2016, 12:34 8 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

    384 Posts


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

    Thread Captain

    1581 Posts

  • #3, by afrlmeSaturday, 23. January 2016, 13:55 8 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

    7278 Posts

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

    Thanks

    Great Poster

    384 Posts

  • #5, by afrlmeSaturday, 23. January 2016, 14:55 8 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

    7278 Posts

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

    Great Poster

    384 Posts

  • #7, by afrlmeSaturday, 23. January 2016, 15:51 8 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

    7278 Posts

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

    Note: I believe it may be all of them.

    Great Poster

    384 Posts

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

    Imperator

    7278 Posts