Running start script on every play? Even on saves?

I have tried various methods on doing this, but have so far failed. The intro screen appears during first play of course, but save games of course do not. Had anyone had any luck with doing this?


I dunno, libraries are too advanced for me, but you can have a peek at this link

Pre- and post-load; pre-save
Sometimes you will want to do something before and after loading, and before saving, perhaps initialising values or calculating derived attributes. For this, you can override the PreLoad, PostLoad and PreSave functions (none has any parameters or return type).
PreLoad fires after the game has found the save-game, but before anything else.
PostLoad before the player is moved to the right location, but after everything else.

https://github.com/ThePix/quest/wiki/Library:-Save-and-Load


After you have learned the library

Create a function named start123
and write all of the codes for your start script in there.

On your game, start script, call function start123.

Trigger function start123 on postload/preload


I have tried various methods on doing this, but have so far failed. The intro screen appears during first play of course, but save games of course do not. Had anyone had any luck with doing this?

I think you're looking for "User Interface Initialisation Script"

When starting a new game, Quest runs the UI Initialisation script and then the Start script.

When starting from a saved game, it just runs the UI Initialisation script.

So if you want something to happen whenever the game is loaded, you should put it in the UI Initialisation script. This is normally used for things like setting up Javascript or custom stylesheets.

The UI Initialisation script is on the "Advanced Scripts" tab of the game, which must first be enabled by checking "Show advanced scripts for the game object" on the Features tab.


I'll look into the potential overrides. Unfortunately, I've already tried using the init script. Though I'm using quest commands for the start screen in tandem with js for initialization of the interface. Is there some execution order between the two perhaps is messing things up? The start screen will show fine on the first run through the init script (when the start script is merged with the init script.), when a new game is started, but when saves are loaded, it's all messed up.


tried both (again)...the library is very complex, and I haven't gotten it to work before, along with another library, and doing it with the init script is just as fruitless...i tried implementing an eventlistener, but no luck. Quest bypasses all the intro code and jumps to the save state (which is really messed up after I do so). Tried executing the intro code both at the beginning and end of the init script. Same result either way. Though, it does work on first play in the init script...but it breaks once loading from a save file. Oh well, kind of giving up. Too bad, my intro is pretty darn cool =) If anyone has any other suggestions, feel free to post. I'd must appreciate it.


Though, it does work on first play in the init script...but it breaks once loading from a save file.

Can you show us the game in question? The UI Initialisation script should run when loading a saved game; so if it doesn't work, there could be something interfering with it. But it's impossible to give any more advice without actually seeing the problem.


Sure...here is the source code: https://pastebin.com/Je6t0tiM. It's a work in progress.


Ah… assuming the intro in the start script is what you're trying to run every time?

Not sure, but I wonder if there's some restriction against putting wait in the UI initialisation script. I'll have to give that a try and see what the rules are.


i think you might be right...as an experiment, deleted everything in the init script aside from the intro code, and it still errored out...showed nothing except for playing the ogg file, which means the rest might be working fine, but the screen clears and shows nothing else, because each description contains a clearscreen command. And oddly, the init script with the intro usually works fine on first run, but on saves it doesn't work. I tried creating an event listener to simulate a wait command, and that does its job, but freezes the game (it could be simply the code itself, or that it interferes with other operations, but I have no idea). I tried redoing some of the init script as JQuery, but that didn't work either. It doesn't seem to matter either way. I'm totally stumped.


Well, after even more experimentation, had the idea of just making a pop-up that shows a version of the intro at the beginning of saves after the game state is loaded. 1st run shows the start screen, no popup, then on saves it switches to a pop-up which is displayed over the reloaded game state. Hey, good enough for me. Was getting burnt out trying to figure out the other way. Now, on to finishing the game. =)


Well this is confusing, I tried various methods and could not get pixie's save/load library and mrangel's "User Interface Initialisation Script" to work.

Basic information about save
https://docs.textadventures.co.uk/quest/about_save.html

Pixie's save/load library
Description:
This have been confusing, basically you need to install library using offline quest app, but you can only test the code after publishing the game, as the code needs a web browser local storage to save the data. I managed to get presave to work, but if preload and postload does not works, then there is not much point, right?
I suspect this library might be broken due to either the quest app engine new updates or the way that web browsers works have changed over the time.
https://github.com/ThePix/quest/wiki/Library:-Save-and-Load
To override the function of postload and etc, you need
https://github.com/ThePix/quest/wiki/Overriding-Functions

mrangel's "User Interface Initialisation Script"
Dscription:
It is already thoroughly explained on how to use it by mrangel, everything makes sense here, but somehow I could not get it to work, I am guessing this script only updates one-time stuffs like user interface and not changing-codes like variables and attributes which was what I was experimenting with.


I have a lame solution, but here it is
Description:
Basically you politely ask the player to click an object verb/enter a specific room/do anything
whenever the player loads a new game, lol.
Then you trigger the script you want to happen on the new "game load".
https://textadventures.co.uk/games/view/57zl3sqjdeoeuqwqok9r5q/test

<!--Saved by Quest 5.8.6836.13983-->
<asl version="580">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="test4">
    <gameid>fd4e0bd3-5e6f-4508-84d9-6979cfb98f24</gameid>
    <version>1.0</version>
    <firstpublished>2024</firstpublished>
    <attr name="feature_advancedscripts" type="boolean">false</attr>
    <inituserinterface type="script">
    </inituserinterface>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <isroom />
    <enter type="script"><![CDATA[
      if (donkey.nose hair< 3) {
        msg ("Description: Your donkey's nose hair is "+donkey.nose hair + "cm long.")
      }
      else {
        msg ("Description: Your donkey's nose hair is "+donkey.nose hair + "cm long.")
        msg ("Are you sure you do not want to cut the nose hair away?")
        MakeObjectVisible (hair trimmer)
      }
    ]]></enter>
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
      <object name="dynamic load game">
        <inherit name="editor_object" />
        <description>After you load a new game, please click trigger once.</description>
        <displayverbs type="stringlist" />
        <inventoryverbs type="stringlist" />
        <trigger type="script"><![CDATA[
          donkey.nose hair = donkey.nose hair+1
          msg ("The game and attributes have been updated.<br/>Do not click trigger again unless you are loading a save file again.")
        ]]></trigger>
      </object>
    </object>
    <object name="donkey">
      <inherit name="editor_object" />
      <attr name="nose hair" type="int">0</attr>
      <displayverbs type="stringlist" />
      <inventoryverbs type="stringlist" />
    </object>
    <exit alias="east" to="room2">
      <inherit name="eastdirection" />
    </exit>
    <object name="hair trimmer">
      <inherit name="editor_object" />
      <visible type="boolean">false</visible>
      <take />
      <displayverbs type="stringlist">
        <value>Take</value>
      </displayverbs>
      <inventoryverbs type="stringlist">
        <value>Drop</value>
      </inventoryverbs>
      <trimthehair type="script">
        donkey.nose hair = 0
        msg ("Job done.")
      </trimthehair>
    </object>
  </object>
  <object name="room2">
    <inherit name="editor_room" />
    <exit alias="west" to="room">
      <inherit name="westdirection" />
    </exit>
  </object>
  <verb>
    <property>description</property>
    <pattern>description</pattern>
    <defaultexpression>"You can't description " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>trigger</property>
    <pattern>trigger</pattern>
    <defaultexpression>"You can't trigger " + object.article + "."</defaultexpression>
  </verb>
  <verb>
    <property>trimthehair</property>
    <pattern>trim the hair</pattern>
    <defaultexpression>"You can't trim the hair " + object.article + "."</defaultexpression>
  </verb>
</asl>

Log in to post a reply.

Support

Forums