Difference between revisions of "AGIWiki/Memory and Script"

Jump to navigation Jump to search
m
Text replacement - "</source>" to "</syntaxhighlight>"
m (Text replacement - "</source>" to "</syntaxhighlight>")
 
(3 intermediate revisions by 2 users not shown)
Line 256: Line 256:
However, script blocking is useful for small bits of code that don't allow the player to save or restore in between:
However, script blocking is useful for small bits of code that don't allow the player to save or restore in between:


<syntax type="C++">
<syntaxhighlight lang="cpp">
#define script_blocked f7
#define script_blocked f7
   
   
Line 269: Line 269:
  reset(script_blocked);
  reset(script_blocked);
  }
  }
</syntax>
</syntaxhighlight>


==== Save Script Position ====
==== Save Script Position ====
Line 276: Line 276:


The script works like this (you wouldn't use this in a game):
The script works like this (you wouldn't use this in a game):
<syntax type="C++">
<syntaxhighlight lang="cpp">
  load.view(10); // script contains view 10
  load.view(10); // script contains view 10
  push.script();
  push.script();
  load.view(20); // script contains view 10, 20
  load.view(20); // script contains view 10, 20
  pop.script(); // script contains view 10
  pop.script(); // script contains view 10
</syntax>
</syntaxhighlight>
To use in a real game, you need to initialise push.script first. This is similar to the first example in blocking script writing (but overkill):
To use in a real game, you need to initialise push.script first. This is similar to the first example in blocking script writing (but overkill):
<syntax type="C++">
<syntaxhighlight lang="cpp">
  if (new_room)
  if (new_room)
  {
  {
Line 299: Line 299:
  pop.script(); // script doesn't contain either
  pop.script(); // script doesn't contain either
  }
  }
</syntax>
</syntaxhighlight>
Here is my version of code to swap the ego's view and still letting the player save the game:
Here is my version of code to swap the ego's view and still letting the player save the game:


In the room logic (will be needed in all rooms):
In the room logic (will be needed in all rooms):
<syntax type="C++">
<syntaxhighlight lang="cpp">
  if (new_room)
  if (new_room)
  {
  {
Line 316: Line 316:
   
   
  ...
  ...
</syntax>
</syntaxhighlight>
Logic 70 - View switching logic. It can be given any number, just make sure it's the same in the calling logic.
Logic 70 - View switching logic. It can be given any number, just make sure it's the same in the calling logic.


<syntax type="C++">
<syntaxhighlight lang="cpp">
#include "defines.txt"
#include "defines.txt"
   
   
Line 367: Line 367:
   
   
  return();
  return();
</syntax>
</syntaxhighlight>


This is a better solution, because the script will have the correct views loaded when a game is restored and the script size will no increase each time the game is saved.
This is a better solution, because the script will have the correct views loaded when a game is restored and the script size will no increase each time the game is saved.
Line 392: Line 392:


Previously known as unknown.172().
Previously known as unknown.172().
These two commands are only available in AGI versions 2.915 and above.
Despite their names, the [[AGIWiki/push.script|push.script]] and [[AGIWiki/pop.script|pop.script]] functions are not stack functions. Pushing the script will save the current script table position. If push.script is called multiple times, it will overwrite the stored script position each time it is called.
Popping the script will restore the script table position. After calling pop.script , the next script entry will be made at the restored position. It is important that push.script be called BEFORE pop.script. Popping the script position without first pushing it could result in unpredictable results since the memory location where the script position is stored may contain an unknown value.
Because AGI relies on the script entries to correctly [[AGIWiki/Saving games|save and restore games]], it is important to exercise caution when manipulating scripts.


=== Script Flags ===
=== Script Flags ===
TrustedUser
2,147

edits

Navigation menu