[Solved]

Argent

(Lost post ahead and I apologise if this has been asked before.)
I know I've been posting here a lot lately, so hopefully this will be the last in a while, but I can't seem to get this thing to work. I'm still a novice when it comes to learning how to program for Quest, so my codes may be way off base, but at this point I don't know if it is or not.

For reference, I'm using text adventure mode but am working on a game that plays in a style similar to gamebook (so no command bar). I am also using the CombatLib made by Pixie for this game. Might be a little helpful if someone is familiar with the library who could help, but also in general I'd like to know if the methods I've been trying works.

(For the "will this code work in general if I try it with other conditions?")
This is currently the general basis for the different codes I've tried, so even if you don't use CombatLib it should still be understandable. I'd like to know which if any of these would work, or am I completely off in my coding?
If the player clicks the choices, then "object1" and "object2" get moved to location "x", but if they don't click it then the objects remain in location "y".

if (object1.parent = x) {
  player.attribute = player.attribute + 1
}
if (object2.parent = x) {
  player.attribute= player.attribute + 1
}
if (player.attribute = 2) {
  msg ("{command:go to start:start}")
}

Main question here is: will this increase the attribute to 2 or because they are if commands, this doesn't work and I have to try another script? Also do these commands work on an object changing it's parent attribute?
Next code:

if (object1.parent = "x" and object2.parent = "x") {
  msg ("{command:go to start:start}")
}

This one gets rid of the necessity for another attribute, but I'm not sure if this would work, or if I have it typed in correctly, since I know "and" and "or" requires boolean expressions/variables.

(This part is specifically for the CombatLib part) In case this, the goal is to have the player learn 2 spells in the character creation section before a new exit appears which will allow them to start the game. I know I could have the spells already be taught to the player by adding a script to the "before entering room" and then just print a message, "you've learnt blah!" which I will do if I can't figure this out. However, I would like to know if this is even possible with spells.
The code in this case reads:

if (spell1.parent = "spells_known") {
  player.spells = player.spells + 1
}
if (spell2.parent = "spells_known") {
  player.spells = player.spells + 1
}
if (player.spells = 2) {
  msg ("{command:go to start:start}")
}

The player.spells is already defined. I'm not sure if spells changing their parent attribute will trigger the scripted response. My main problem is that I can't get the player.spells attribute to increase in number. This may be a problem, but I'm not sure: the spells are scripted to move into the room before the player enters the room.
I also know that if you attempt to learn a spell twice it should print the message "Er, you already know that one!" However, if I click on learn spell the first time, it works, but if I click on the same learn spell link again, it gives me "I can't see that. (spellnamehere)". Is that because I'm moving the spells into the room in the first place and it's getting moved to "spells_known" after, or is something else causing the problem, or is this function not working properly?

tl;dr How do I force a player to click all previous options before giving them a new option/exit? Also, can scripts work if an object's parent attribute changes?


hegemonkhan

here's a guide I made on the "bread and butter of quest programming (Attributes and the 'if' Script usage):

http://textadventures.co.uk/forum/samples/topic/5559/attributes-and-if-script-guide-by-hk (this will answer most of your coding/syntax questions, there's a lot of info, but it's a bit of reading, also this was years ago, when I was still leanring the basics of programming, so I got some things confused such as the operators... at that time I didn't understand the difference between 'bit' and 'logic' operators, so if you see 'bit' just replace it with 'logic')

here's a step by step guide on Attribute basics (including on using status attributes):

http://textadventures.co.uk/forum/quest/topic/5387/i-really-need-help#37375

my List and Dictionary Attributes guide:

http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk

moving around without Exits:

http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk (this code is old and poor/bad, has some mistakes/inefficient, as this was me learning how to use lists/dictionaries, lol):

http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk

more code that you can study (again this is poor/bad code), and/or get ideas on how to do various things with quest's coding capabilities/Functions/etc:

http://textadventures.co.uk/forum/samples/topic/4988/character-creation-crude-code-and-sample-game


there's a few 'constant* firing/activating' built-in methods:

http://docs.textadventures.co.uk/quest/change_scripts.html

  1. the special 'changed' Script Attribute, an example:
<object name="NAME_OF_OBJECT">
  <attr nam="NAME_OF_ATTRIBUTE" type="TYPE_OF_ATTRIBUTE">VALUE_OF_ATTRIBUTE</attr>
  <attr name="changedNAME_OF_ATTRIBUTE" type="script">
    // WHATEVER scripting
  </attr>
</object>

here's an example using the built-in 'parent' Object reference Attribute (this is what actually determines containment heirarchy and thus the effect of moving Objects around during run-time/game-play):

player.parent = room // the 'player' Player Object is set/placed/contained within in the 'room' Room Object
player.parent = room2 // the 'player' Player Object is now set/placed/contained within the 'room2' Room object, effectively moving it from 'room' to 'room2'

which is the same as if you used the 'MoveObject' helper Function (underneath, the 'MoveObject' Function is just changing the Value of the 'player' Player Object's 'parent' Object reference Attribute from 'room' to 'room2'):

player.parent = room
MoveObject (player, room2)

<object name="room">
</objct>

<object name="room2">
</object>

<object name="player">
  <attr name="parent" type="object">room</attr>
  <attr name="changedparent" type="script">
    msg ("Whenever your built-in 'parent' Object reference Attribute's Value changes, this msg script is run/activated.")
  </attr>
</object>
  1. The 'Turnscript' Element

http://docs.textadventures.co.uk/quest/elements/turnscript.html

  1. The 'Timer' Element

http://docs.textadventures.co.uk/quest/elements/timer.html


if you still need help, and/or need help with my links and/or anything explained or whatever, let me know.


The Pixie

To quickly find out how many spells the player knows do this:

spellcount = ListCount(GetDirectChildren (spells_known))

spells_known is effectively a room; this grabs all the things in that room, and counts them. Note that spells_known should not be in quotes; it is not a string.

Then you can do this:

if (ListCount(GetDirectChildren (spells_known)) = 2) {
  msg ("{command:go to start:start}")
}

How this will work too (and is probably simpler):

if (object1.parent = spells_known and object2.parent = spells_known) {
  msg ("{command:go to start:start}")
}

The question then is where to do it. Do you need to test this when the player learns either spell?


Argent

hegemonkhan: Thank you very much for all the links! I've actually already looked through a few of them before in trying to get it this to work, but I'll definitely take a look at the other ones and let you know if I have any questions.

I do have a question regarding timers though. I've tried to create a timer and gave it a name, but when I try to enable it or use it in general, the name I gave it doesn't show up in the second drop down menu box, the box just shows up as blank. I'm not sure if I'm doing something wrong or if I just don't know how to use the script properly. What am I doing wrong if I am, or what else do I need to do in order to get the name to show up? I've tried writing in the code with the name but it gives me an error each time as well.

Pixie: Thank you for helping me out again, hopefully I'm not causing too much of an inconvenience with all this. I did figure out that the spells once learnt go to the room spells_known. I have tried the 2nd simpler code before without the quote marks, but the link to the start didn't show up. It seems to just stop after the player clicks both learn links and can't progress further. I also tried the first code you provided me with the listcount, but it also failed. I'm guessing I'm putting the code in the wrong place?

This is my current code for the page:

msg ("")
msg ("The Elves are known to be able to adapt to most regions of the world, making them generalists when it comes to elemental magic.")
msg ("")
msg ("You may now learn the following spells:")
msg ("{command:learn Cancel:Cancel}")
msg ("{command:learn Zap:Zap}")
if (Cancel.parent = spells_known and Zap.parent = spells_known) {
  msg ("{command:go to start:start}")
}

My plan was to have the start pop up right after the player learns both spells, and possibly print a message if the player learnt only 1 spell that they need to learn both in order to continue.

I tested the spellcount variable and if the spells haven't been learnt yet it does print as 0, however, if I scripted the spells to already be moved into the spells_known room before the player enters the room, then the count does show as 2. I believe it does work if the player learns the spell, but I'm not sure. I'm still not getting the message: "Er, you already know this one!" if I attempt to learn it again. Instead, I get "I can't see that. (spellname)" I was wondering why that was the case? Thank you again!

Edit: Also if I attempt to look at a spell after I've learnt it, it gives me "I can't see that." because it was moved to spells_known, the character doesn't have access to spells known so I assume that is supposed to happen. But is there a way the character can see it even after they've learn it? (I'm really sorry for all the questions, I've read through the guide but I couldn't find anything on this, I'm not sure if I'm just not doing something right.)


hegemonkhan

I'm not that familiar with Timers and the built-in quest stuff as to why your Timer isn't showing up.

My only guess is possibly where you got the Timer located/placed... if it's not a, coding mistake or whatever mistake, on your part

there's two locations:

global (game wide, no matter what room you're in: not room specific/contained) and room specific (room contained: it only is in effect when you're in its room, when you're not in its room, it's like it doesn't exist)


this is your game:

<asl version="550">
  // your mass of full game code/content
</asl>

so, anything directly nested (indented) within the 'asl', is 'global', for example, a Timer:

(see how the 'game', 'include refs', 'object', and 'timer' are all indented the same amount?

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game="XXX">
    // blah Attributes
  </game>

  <object name="room">
  </object>

  <timer name="global_timer">
    // optional: <enabled /> // if you want the Timer to be enabled at the start of your game
    <interval>SOME_NUMBER/INTEGER_VALUE</interval>
    <script>
      // blah scripting
    </script>
  </timer>

</asl>

or, you have a local Timer (specific-to/contained-within an Object):

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game="XXX">
    // blah Attributes
  </game>

  <object name="room">

    <timer name="local_timer">
      // optional: <enabled /> // if you want the Timer to be enabled at the start of your game
      <interval>SOME_NUMBER/INTEGER_VALUE</interval>
      <script>
        // blah scripting
      </script>
    </timer>

  </object>

</asl>

you can also via scripting, enable/disable Timers (and also Turnscripts), when-ever/where-ever you want:

Enable Timer (global_timer)
Disable Timer (global_timer)
Enable Timer (local_timer)
Disable Timer (local_timer)

for example:

<asl version="550">

  <include ref="English.aslx" />
  <include ref="Core.aslx" />

  <game="XXX">
    <attr name="start" type="script">
      EnableTimer (global_timer)
    </attr>
  </game>

  <object name="room">
  </object>

  <timer name="global_timer">
    <interval>1</interval>
    <script>
      msg ("and now we're disabling timer")
      DisableTimer (global_timer)
    </script>
  </timer>

</asl>

Argent

hegemonkhan Thanks very much! It did seem like the problem was where it was located, I got that fixed now.

I'm still however having an issue with getting the start link to either show up or unlock. It may be an issue with me not being able to see the spells when I think I should be able to, but I'm not quite sure. I have tried a few of the other methods and looked at the links you've provided but I guess I'm still doing something wrong.


hegemonkhan

just more on the aslx/xml-like structure:

vertical heirarchy doesn't matter, except obviously with the '<include ref="XXX.aslx" />' library files (quest is a very advanced engine, as it is made up of library files, so a good programmer, can potentially even create their own unique quest engine), as these are used to initialize ("build up") the game and/or quest/game engine, and so the 'include ref' has to go first (at the top), and also probably the '<game name="XXX">content</game>' Game Settings Object has to then go after (below) the 'include ref', but after these, the vertical heirarchy doesn't matter.

"nesting" (indenting / horizontal) heirearchy DOES matter, as this is it's containment heirarchy, and for sripting, it's 'order of operations/scripts'

// your game, the 'asl' GAME OBJECT (main/root OBJECT that holds everything), the entire game code/contents:

<asl>
  // mass of game code/content
</asl>

// your library files (game engine files and/or patch-xpac-mod files) for game/game-quest-engine initialization, for example the built-in default ones:

<include ref="English.aslx" />
<include ref="Core.aslx" /> // this is just a hub file of all of the various individual 'core' files

// your 'game' Game Settings Object:

<game name="XXX">
  // various Attributes: author, version, firstpublished, category, difficulty, cruelty, 'start' Script, etc
</game>

// all your other various Elements: Objects, Verbs, Commands, Functions, Turnscripts, Timers, Object Types, etc

// note that quest requires a (specified) Player Object, such as the default 'player' Player Object, and for it to be within a Room Object (such as the default 'player' Player Object being inside of 'room' Room Object for a default new game), as the software is coded around this design, see the link below

http://docs.textadventures.co.uk/quest/asl_requirements.html


the default new game code:

<asl version="550">
  <include ref="English.aslx" />
  <include ref="Core.aslx" />
  <game name="NAME_OF_GAME">
    <gameid>SOME_GENERATED_RANDOM_HASH/STRING</gameid>
    <version>1.0</version>
    <firstpublished>2017</firstpublished>
  </game>
  <object name="room">
    <inherit name="editor_room" />
    <object name="player">
      <inherit name="editor_object" />
      <inherit name="editor_player" />
    </object>
  </object>
</asl>

Creating your own library files is easy:

a library file (it uses/requires the same 'XXX.aslx' extension just as a game file does):

<library>
  // your code content that can/will be added to a game file, be it: a single object, or an entire game system, or even your own game engine
</library>

yep, that's all you got to do, to create/code in a library file (super simple)... though your library file's content/code is another matter...

to then add/use the library file in a game file:

  1. the 'XXX.aslx' Library file itself must be in the same folder/location as either the quest.exe and/or your 'XXX.aslx' game file
  2. you got to add (reference) it into your game file, via using the 'include ref' tags (or the GUI/Editor's options/tabs for adding library files) via within your 'xxx.aslx' game file's code itself
  3. also, the order of library files matter, if you've ever played a game that you can add mods/patches to it, you should know that the order that they're initialized matters, as initialization means that the game is "built up" on the library files, so they need to be used in their proper order, otherwise you'll get errors.
  4. also there's the possible issue of compatibility, especially when using lots of advanced library files and/or badly made ones.

ask if you got any questions, please ask!


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums