Lua - dynamically creating scene objects

  • #1, by F_KalMonday, 11. January 2016, 22:55 5 years ago
    Hi!
    I'm new to VS and even "newer" to Lua (I have some fair C/C++ experience - though a bit dusty).
    At this point I'm trying to get a grasp of what can be done, and what can't be done with VS!

    Dynamic Objects in VS via Lua


    Question


    I was wondering if it's possibly to create scene-object instances on demand,with a dynamically assigned "object area", their own actions, and the ability to put them into the inventory.

    A practical example


    A proof-of-concept I'm trying to create is:
    a Library scene that has bookcases with shelves full of books. These books should be dynamically instantiated with
    - a random title made out of words contained in a table
    - a pair of images (the book spine for representing the book on the shelf and the cover for its representation in the inventory) randomly picked by a table of coupled-together filename-paths.
    - other than the title, they should also carry some other unique properties(variables?) eg. number of pages and book weight
    - on scene init, they are randomly generated and stacked in the shelves, one next to the other
    - they can be looked-at, picked-up (leaving their place empty), and placed as items into the user's inventory. Later on, the user should still be able to know the title, weight, and number of pages for the books he is carrying and use them in a puzzle where weight, pages number and title are important.
    - Be able to save the picked-up books with their properties inside the savegame [optional]
    - Be able to save the whole unique Library scene with its books inside the savegame, so the user can revisit it. [my guess is this isn't feasible at all]

    Any lead on how to do that?


    For now I'd be more than happy if somebody pointed me towards the right direction regarding a)object instantiation, b)(re)setting a scene object image via code, c)defining the object area via lua, e)linking actions to scene objects via lua.
    If I got the info on Data Structures wiki correctly,it seems b) to e) are not scriptable. If I got it right, only their position can be changed via lua.

    Alternatively what is the possibility of dynamically creating "multiple copies" of an pre-existing scene objects and only modifying their scriptable properties? For instance, if I can't change the image filename through lua, how about I create in the editor instances of all different book cover designs, and instantiate these instead? Of course they have to be separate instances, since two books may share the same cover design and hotspot area, but the title/pages number/weight, should be unique.

    If instances are totally unsupported, I wonder how would you tackle the "(seemingly) random library" example? Would you painstakingly create all books in the editor and then have them shuffled around on scene init?

    Would also appreciate if somebody went through the list of features I imagined for this library scene and comment on the feasibility of each one of these. A short comment in the lines of "I think yes - I'd look into ___ for that" or "no - can't think of way to achieve this"

    Thank you for your time!
    -Fotis

    PS. Please feel free to take your time; I'm not in the making of my next blockbuster wink
    I'm merely trying to learn visionaire studio and thought that since I didn't find anything about new/constructed instances of scenes or scene-objects in the forums, I could raise the question, provoking an answer by others who have a better understanding of VS and its philosophy - hopefully this will be helpful for other n00bs too smile

    PS. I remember Memoria by Daedalic had a "random" forest labyrinth puzzle with many rooms(scenes). My guess is they had one room with all possible assets already created in the editor and depending on which room you were previous in, and which direction you were exiting towards now, they were displaying only the assets that made up the next individual room, giving the illusion of travelling through rooms, while you were merely exiting from one side and reentering from the other side...

    Forum Fan

    107 Posts


  • #2, by SimonSTuesday, 12. January 2016, 01:00 5 years ago
    Hi!

    You can't create scene objects or such in the player.
    There are these options for you:
    - prepare a scene with placeholders and use values and different objects for images (with conditions)
    - create a custom render function, to render all the books, that will be a little more complicated
    - do everything with text only
    I would recommend you option 1, building a library that can be big can only be done with option 2. Maybe a combination.

    Thread Captain

    1380 Posts

  • #3, by F_KalTuesday, 12. January 2016, 05:01 5 years ago
    @SimonS Thank you for such a prompt reply!


    - prepare a scene with placeholders and use values and different objects for images (with conditions)

    yes, that seems rather straightforward!
    Is there some (lua) way, that would allow me set the image propery of an object via code (eg. a red book, a green book, an old tome, a small book, a burnt book etc)? I've thought of assigning a different frame for each image and jumping to the one that I wish to use - but I wonder if there is some more straightforward way: a function that allows you to set an image perhaps?


    - create a custom render function, to render all the books, that will be a little more complicated

    custom Render functions? That sounds an interesting feature! Could you point me towards some sample code, thread, tutorial or general idea of what a custom render function in VS can be or how one can be written in VS's lua?

    Thank you again!
    -Fotis

    Forum Fan

    107 Posts

  • #4, by afrlmeTuesday, 12. January 2016, 05:25 5 years ago
    What you are wanting to do is quite complicated. VS is not game maker, so unfortunately there is no instance create / destroy function or use actions belonging to a parent object.

    You can create stuff in the editor itself then create some Lua tables & then randomize the order of the tables data to determine the titles / colors of each book. As for the colors you could probably create each book as an animation & then force the animation frame or determine which animation should play for each book. Animation approach would definitely be faster than creating a single object per book & per book color.

    The titles of the books (I'm assuming you are referring to the action text displayed on mouse over) could be edited to suit using the registerHookFunction for the action text flag. Quick note: updated object / action text names are not stored inside of save game files, thus you would need to check / update the name of books on mouse over actions.

    Adding those books to the inventory would require you to check the table to make sure it adds the correct book to inventory. You would set a specific animation frame or unload the current animation for the book you just removed from the book shelf.

    P.S: sorry this is mostly theory & is not exactly easy to explain. I roughly have an idea of how I might go about sorting something like this out, but explaining it is a completely different ball game altogether.

    P.P.S: since the latest build of VS, we are now supposed to be able to directly draw text & images via Lua script, however that still leaves out the objects, object interaction polygons & actions belonging to said object.

    Imperator

    6846 Posts

  • #5, by F_KalTuesday, 12. January 2016, 08:35 5 years ago
    @AFRLme, your "rough idea" has been clear enough - Thank you!
    I also finally got what registerHookFunction is meant to do! Very useful!

    P.P.S: since the latest build of VS, we are now supposed to be able to directly draw text & images via Lua script, however that still leaves out the objects, object interaction polygons & actions belonging to said object.


    I see! These drawing functions seem interesting; Any page where I can see their syntax/samples?

    Thank you!

    Forum Fan

    107 Posts

  • #6, by afrlmeTuesday, 12. January 2016, 12:25 5 years ago
    No unfortunately I haven't got round to asking Simon to provide examples for me to add to the wiki, nor has he added any to the wiki himself yet. However I believe there were some examples added to the recent thread about the release of VS 4.2.5. wink

    * edit: the examples (sort of) are on the second page @ http://www.visionaire-studio.net/forum/thread/visionaire-stu... - I've no idea how David managed to break the formatting in the message he posted, but there's some examples of how to draw things with Lua as well as how to grab & display things from the internet using libcurl. All useful stuff I guess.

    Imperator

    6846 Posts

  • #7, by F_KalTuesday, 12. January 2016, 14:31 5 years ago
    Thank you so so so much @AFRLme!
    I found it on the 2nd page as you indicated - I'll go through the whole thread and see what other interesting stuff I can learn wink

    Forum Fan

    107 Posts

Write post