[SOLVED][LUA] Change character scene question

  • #1, by sebastianSunday, 09. October 2016, 19:15 4 years ago
    Hello there mates and matettes,

    I've got stuck again and i don't know why my solution doesn't work.
    I want to teleport a char (CurrentCharacter) to a specific scene out of a lua table entry.


    while setting the position (coordinates) of the char works great:
    char:setValue(VCharacterPosition, {x = some_x_coord , y = some_y_coord })
    1
    2

    I try to switch the character to another scene BEFORE said repositioning:
    local char =  getObject("Game.GameCurrentCharacter")
    char:setValue( VCharacterScene, scene_table[selected_room])
    1
    2
    3


    "scene_table[]" is a lua table with each room in the game as an entry. It contains the whole object, not only the name via :getName().
    "selected_room" is an index from 1 to #scenes that exist.

    When executing the script I get an error: :15: attempt to concatenate a userdata value

    Any idea how i throw my wanted character to another scene?


    kind regards
    Sebastian

    Thread Captain

    2337 Posts


  • #2, by afrlmeSunday, 09. October 2016, 19:22 4 years ago
    Did you try adding return in front of the getObject?

    Imperator

    6842 Posts

  • #3, by sebastianSunday, 09. October 2016, 19:28 4 years ago
    nope... didn't know why. When i print(char) directly after getting the object, it returns my char-name + tupel (tableid/objectid). So char is right. Also when i print out scene_table[selected_room] i get the correct roomname + tupel

    Thread Captain

    2337 Posts

  • #4, by afrlmeSunday, 09. October 2016, 19:35 4 years ago
    Maybe need a delay between teleporting & updating character position?

    Imperator

    6842 Posts

  • #5, by sebastianSunday, 09. October 2016, 19:40 4 years ago
    The error comes up even before setting the chars position.
    The problem is this line:
    char:setValue( VCharacterScene, scene_table[selected_room])
    1
    2

    Do in need the objects itself in there or only their names?

    Thread Captain

    2337 Posts

  • #6, by sebastianSunday, 09. October 2016, 19:58 4 years ago
    Haha, got it:
    I changed the "selected_room" to return the name and not the scene object
    The function has to be
    char:setValue( VCharacterScene, Scenes[scene_table[selected_room]])
    1
    2

    Thread Captain

    2337 Posts

  • #7, by afrlmeSunday, 09. October 2016, 20:26 4 years ago
    Data structure says it's a link so should be full path to scene.
    Scenes["name"]
    getObject("Scenes[name]")
    1
    2
    3


    * edit: sorry I thought I'd posted my reply ages back & went out for a bit & when I came back I saw that it hadn't processed. I see you figured it out anyway. smile

    Imperator

    6842 Posts

  • #8, by sebastianSunday, 09. October 2016, 20:35 4 years ago
    Yep, that was my problem. Thought that the Scene-Object is already enough to tell the engine: "hey, thats a scene, boi!"

    The cool thing is that i have only one object on the debug screen which deals with the teleports (instead of one object for each entry).
    A click on it checks the position of the cursor on the menu and picks the right teleport scene from a table which got autofilled before with all displayed scenes.
    Then the char gets repositioned to the X+Y coordinates of an object called "debug_teleport" which is named on each scene the same but with different positions.
    The list gets autofilled with every new scene, so the only thing i have to do when adding a new scene is
    adding a debug_teleport object in the new scene and set its coordinates

    https://cl.ly/0k1o1635310C/2016-10-09_20.37.57.png

    Thread Captain

    2337 Posts

  • #9, by afrlmeSunday, 09. October 2016, 21:14 4 years ago
    Damn. I couldn't really be bothered with all the effort of creating a full debug system. I find it easy enough to run SnakeTail alongside of VS & use the odd key event for certain things. Typing something into the developer console (tab) is easy enough for me too.

    Imperator

    6842 Posts

  • #10, by sebastianSunday, 09. October 2016, 21:51 4 years ago
    the debug screen in my project is only for quick teleport and starting the game from specific points later (+ some misc stuff).

    Thread Captain

    2337 Posts

Write post