Set character to new scene (Lua)

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

    Great Poster

    351 Posts


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

    Thread Captain

    1383 Posts

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

    6862 Posts

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

    Thanks

    Great Poster

    351 Posts

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

    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
    1
    2
    3
    4
    5
    6

    ... I think you get the idea. smile

    Imperator

    6862 Posts

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

    Great Poster

    351 Posts

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

    6862 Posts

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

    Note: I believe it may be all of them.

    Great Poster

    351 Posts

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

    Imperator

    6862 Posts

Write post