definition scripts?

  • #1, by gustySaturday, 14. December 2013, 08:12 7 years ago
    I'm browsing in the Scripts menu in VS and I'm reading something interesting I didn't know about before:

    definition script - Definition scripts should only contain functions and global variables. These scripts are executed at game startup therefore making the functions available through the whole game



    If I get it right, there is a possibility to have a script which runs on the background the WHOLE time during the game? And it would performs actionparts anytime when some "if" is fulfil? It would make no difference in what scene would player be at the moment or whatever he would be doing (=standing on the place doing nothing, performs some other actionscript, looking into his inventory..). Am I getting it right? If so, could you please tell me what exact text should I write into the Script window for a script like that:

    If value "ValueX"=2
    Change condition "ConditionX" to false
    End if
    1
    2
    3
    4


    And second question: Is it possible to have a simple script which would change value by the real time? Let say I would like to have a script which would add value 1 to my "valueX" EVERY hour of play time during the WHOLE game. And it would work with load/save system correctly.

    Forum Fan

    159 Posts


  • #2, by AlexSaturday, 14. December 2013, 12:30 7 years ago

    If I get it right, there is a possibility to have a script which runs on the background the WHOLE time during the game?


    No, as the documentation says: "These scripts are executed at game startup". so they are only executed once. But you can easily register your own function for the main loop event handler which is basically what you want:
    http://wiki.visionaire-tracker.net/wiki/RegisterEventHandler


    And second question: Is it possible to have a simple script which would change value by the real time? Let say I would like to have a script which would add value 1 to my "valueX" EVERY hour of play time during the WHOLE game. And it would work with load/save system correctly.


    you could also do this in the main loop event handler. use the getTime command to reset the timer at game startup
    http://wiki.visionaire-tracker.net/wiki/GetTime
    with reset=true and later on in the main loop event handler you can check if more than 1 hour has passed.

    a simpler solution without scripting would be to start an action which looks like this:
    - Pause for 60 minutes
    - set value 'valueX' + 1
    - jump to action part #1

    Great Poster

    378 Posts

  • #3, by gustySaturday, 14. December 2013, 16:55 7 years ago
    But you can easily register your own function for the main loop event handler which is basically what you want


    Well thanks, but ehm, could you please tell me how to setup such a thing? The only thing (except the time feature which I could do without scripting and I will probably do) I would like to have on background processes in my game is simple event (or function or how you call it) which controls the whole time of the game IF some value is this number and if so, it changes the specific condition, if no do nothing but still running on the backgound. So the example from my first post:

    If value "ValueX"=2
    Change condition "ConditionX" to false
    End if


    Now I have absolutely no idea how can I achieve this with registerEventHandler. How the script would look like and even where should I write it in Visionaire? red

    Forum Fan

    159 Posts

  • #4, by afrlmeSaturday, 14. December 2013, 17:23 7 years ago
    to have something constantly running in the background performing if queries we need to use the mainLoop handler & a function which contains the actions/queries etc that we want/need to loop.

    could you please explain in detail exactly what you are wanting this script to do? so I have a better understanding of what you are wanting & then maybe I could provide some script examples or a script you can drop into your project.

    Imperator

    6842 Posts

  • #5, by gustySaturday, 14. December 2013, 17:38 7 years ago
    Well I'm thinking about implementing some RPG elements into my game. Let say I would like to have a hunger system. So every one hour (or whatever time unit I would be comfortable with) value -1 would subtract from an initial "hunger value" (which is on let say 5 when the game starts). If that value would be on "0", my character would die, game over. But if the player would perform some specific actionparts in specific scenes during the game (eating a pie in kitchen scene for example) it would manipulate the "hunger value" (adding and subtracting). So basically that is what I would really love to achieve.

    Forum Fan

    159 Posts

  • #6, by afrlmeSaturday, 14. December 2013, 20:35 7 years ago
    that is simple enough to do in editor with values & a couple of if queries to check the current value.

    as for the timer part: the simplest method which requires no scripting is to use the pause action part in combination with the jump to part action. the jump to part action is essentially for creating loops in the editor which can be done by jumping back up to an if query. if the query is met then perform the actions inside of the query else end the loop by skipping past the if query. any actions listed after the if query will never be performed unless the loop is broken.

    hmm thought has occurred - say your character managed to perform the required action(s) would the timer also be reset when +1 has been added to the value?

    I don't see any real reason to use lua script for this & we don't have a proper pause/delay/time method. getTime() function is ok but works in milliseconds & you can only use 1 instance of it. also you can not stop or pause it, only reset it back to 0.

    Imperator

    6842 Posts

  • #7, by gustySaturday, 14. December 2013, 22:38 7 years ago
    Well well well again because of my lack of knowledge of VS I figured out today the miracle of "Call action". So now I can have a hundred of "Call action" actionparts inside the "At begin start following action" in the Game properties so I can check every single value I want everytime during the game. It is such a beautiful thing. Like you said every action like that must ends with "Jump to action part" which makes it like a loop and I also realize that you must begin with a Pause actionpart (I'm using 1ms). When you would start with "If something", then "Jump to actionpart" doesn't work.

    But after all I would like to know what is the practical difference between using Call actions inside the "Start action" in compare to "definition scripts"? Are there any significant differences?

    And my last question is how exactly the "Pause" actionpart works? I mean would it make difference for player with a strong computer and player with a slow computer? Can I really use "Pause" like a reliable timer feature?

    Forum Fan

    159 Posts

  • #8, by gustySaturday, 14. December 2013, 22:56 7 years ago
    hmm thought has occurred - say your character managed to perform the required action(s) would the timer also be reset when +1 has been added to the value?


    No, no reset. Example: My character is starving as the player plays (=substract 1 from initial value every hour). But he can eat an apple which add 1 value to "hunger status". He can also eat some proper meal which add 5 value to initial "hunger value". But real time substracts that value on regular basis really slowly during the whole game. Even after he just eat something that value go down regularly by the time. I know that human metabolism works a little different than that but what the hell smile

    Forum Fan

    159 Posts

  • #9, by afrlmeSaturday, 14. December 2013, 23:11 7 years ago
    indeed, which was why I asked if eating something would reset timer back to beginning or by x amount of time.

    hmm I have just considered that resuming the timer from where it left off on game load might add some complications. but if you don't mind it being completely spot on to the second then it shouldn't pose much issue.

    Instead of setting a pause value for 1 hour it might make more sense to set the pause value per second or minute & then incrementing a value up to 60 & then resetting back to 0 but if you wanted to do it by seconds then you would need 2 values. every time the seconds values reaches 60 we run an if query to check value of the minutes value to determine if we should add 1 to current value or add 1 & deduct 1 from the hunger value.

    Let me know which time method you prefer.

    Imperator

    6842 Posts

  • #10, by gustySaturday, 14. December 2013, 23:52 7 years ago
    Exactly what kind of complications do you have on mind? I'm listening. Anyhow I'm not making some survival game so I doesn't need accuracy of seconds or even minutes I would say.

    Forum Fan

    159 Posts

  • #11, by afrlmeSaturday, 14. December 2013, 23:58 7 years ago
    the complications I had in mind were that if you were to use a pause value of say 60 minutes, then if you quit the game & then re-opened it & loaded the game then it would not resume from the where the pause time left off, it would restart from the beginning which is why it would be more ideal to use seconds or minutes & store the current time inside of a value which would allow you to pick up from where you left off. Also if you liked, you could add a condition to prevent timer from working if current scene is a menu or during a cut-scene or whatever.

    *edit: it's late now but I will try & sort you out an example the morrow.

    Imperator

    6842 Posts

Write post