Random Scene Timer?

  • #1, by louis-durrantSunday, 28. May 2017, 10:43 8 years ago
    This is probably a fairly niche question, but I'm taking my game to be shown at a show over the coming week. Obviously a linear story game doesn't lend itself well to hundreds of people walking past and playing with it for a minute or two.

    I had the idea that on every scene a timer starts if the game detects that no input (the game is all left click) has been recieved. Once the timer is up, a random scene will be shown.

    I'm feeling confident about the random scene part of the scripting, but unsure about something like "if no mouse click has been recieved for 5 minutes, set value to random" etc. Obviously I could just set a timer to each scene but I don't want to cut people off mid-play.

    I'm very beginner at writing scripts, so any help would be much appreciated smile

    Thanks!

    Newbie

    12 Posts


  • #2, by afrlmeSunday, 28. May 2017, 12:19 8 years ago
    Yeah it would be possible. Not got my thinking cap screwed on properly at the minute though - still half asleep; or maybe it's the bloody heat making it hard to concentrate.

    But yeah, you could use a mouse event handler to listen out for any mouse movement which you can use to reset the getTime() function, would probably be the simplest solution. Changing to a random scene on the other hand might be a bit of a pain as you would also need to adjust various conditions/values accordingly & add/remove inventory items, etc. Might be simpler if you play through your game/demo yourself & create an autosave at the beginning of each scene, then using a mainLoop event you can check when time equals 5 minutes (in milliseconds - sorry, though you could convert it with one of the time conversion functions I shared on the wiki into minutes/seconds if you prefer) then call a called by other action that contains a set random value, then a bunch of if queries along the lines of...

    if value "rand_scene" is 1
     load autosave #1
    end if
    if value "rand_scene is 2
     load autosave #2
    endi if
    ... etc

    Anyway, hope this helps. Sorry if it's not very clear. As I said, I'm tired & it's boiling hot here at the minute.

    Imperator

    7285 Posts

  • #3, by louis-durrantSunday, 28. May 2017, 14:51 8 years ago
    Yeah it would be possible. Not got my thinking cap screwed on properly at the minute though - still half asleep; or maybe it's the bloody heat making it hard to concentrate.

    But yeah, you could use a mouse event handler to listen out for any mouse movement which you can use to reset the getTime() function, would probably be the simplest solution. Changing to a random scene on the other hand might be a bit of a pain as you would also need to adjust various conditions/values accordingly & add/remove inventory items, etc. Might be simpler if you play through your game/demo yourself & create an autosave at the beginning of each scene, then using a mainLoop event you can check when time equals 5 minutes (in milliseconds - sorry, though you could convert it with one of the time conversion functions I shared on the wiki into minutes/seconds if you prefer) then call a called by other action that contains a set random value, then a bunch of if queries along the lines of...

    if value "rand_scene" is 1
     load autosave #1
    end if
    if value "rand_scene is 2
     load autosave #2
    endi if
    ... etc

    Anyway, hope this helps. Sorry if it's not very clear. As I said, I'm tired & it's boiling hot here at the minute.

    Cheers for battling through the heat smile

    Would you be able to eloborate on the mouse event handler or point me towards somewhere where I could read more?

    My game is very simple (no items), and I've already got an Action that resets all values and conditions, so I'm feeling confident it shouldn't be any trouble setting a value to a random number, and then sending the character to a scene assigned that respective number.

    Newbie

    12 Posts

  • #4, by afrlmeSunday, 28. May 2017, 16:03 8 years ago
    here's a basic mouse event handler (can only have 1 mouse event handler per project)...

    function mouseEvt(eventType, mousePosition)
     getTime({flags=1, reset=true}) -- reset timer back to zero
    end
    
    function check_idle()
     if getTime() >= 300000 then -- 5 minutes (in ms)
      startAction(Actions["random_scene"])
      getTime({flags=1, reset=true}) -- reset timer back to zero
     end
    end
    
    registerEventHandler("mainLoop", "check_idle")
    registerEventHandler("mouseEvent", "mouseEvt")
    


    Create the script above as a definition script. Create a called by other action somewhere & name it "random_scene" (without the quotation marks). Create a value somewhere that you can use for setting a random value. Create some actions & if queries like I mentioned in my last message for selecting a random scene / resetting game, etc.

    I think that's about it. Wouldn't it be simpler if you had it reset game & go back to the main menu? You can reset the game by reloading the main vis file with the replaceGame() function. I think it works something like...
    replaceGame("data.vis") -- replace data.vis with name of vis file located in game root folder

    Imperator

    7285 Posts

  • #5, by louis-durrantSunday, 28. May 2017, 17:01 8 years ago
    Amazing, thank you so much!

    I'll report back with how I get on smile

    Newbie

    12 Posts

  • #6, by louis-durrantMonday, 29. May 2017, 12:47 8 years ago
    So I've set the action "random_scene" to just simply change the current scene so I can test if the script triggers it for now.

    Unfortunately the script only seems to be triggering the action while transitioning between scenes, and only if the timer is set to be smaller than the time to fade.

    I hope I haven't overlooked anything?

    Newbie

    12 Posts

  • #7, by afrlmeMonday, 29. May 2017, 13:32 8 years ago
    Can you post me some screenshots of how you've set it up please or zip/rar/7zip up your project & send it to me via pm? - only if you want.

    I probably didn't explain it too well & without images or a video it's often hard to understand something written in only text.

    Imperator

    7285 Posts

  • #8, by louis-durrantMonday, 29. May 2017, 13:50 8 years ago
    Sent smile

    Newbie

    12 Posts