Ending game when all necessary items are found

So i am almost finishing my game, and i need one last thing to finish it.

So in the game you need to find the necessary items, then it'll finish (yep, it is pretty easy).
But i don't know how to do this! Help!

If someone can, please tell me how to do it.


Hi, Take a look at the following threads, they might give you some ideas on how this problem can be achieved.

http://textadventures.co.uk/forum/quest/topic/am3sb25pokopvsrndjkkbg/multiple-item-requirements
http://textadventures.co.uk/forum/quest/topic/7ubpqkoud0kqgppbza5azg/end-game-when-player-has-certain-items-picked-up-in-a-random-order
http://textadventures.co.uk/forum/quest/topic/z3z_6lw3vuwigm7tnc5fcq/adding-objectx-to-list


Here is what I do. There is a bit of code at the end of this if you want to look at that.

  1. On 'objectA' click on the attributes tab.
  2. Click the + (add) button next to attributes. Name it something like 'ItemsCollected'.
  3. At the drop down box below, select 'integer' and set it equal to the number of necessary items your player will need to find. I'm going to pretend there are 5, so I will set the integer attribute to 5.
  4. You will now see on this attribute an option to select 'Add Change Script'. Click it. Something will pop up in theattribute box. Ignore for now.
    I will assume also that the player will pick up these objects. If they are not taking the object, you can place the scripts below wherever you need them.
  5. Go to each of the objects the player needs to find and click on the inventory tab and click on the default behavior under 'Take' and change it to Run Script.
  6. Choose a 'First Time' script. This is CRUCIAL because if the player drops the item and picks it back up the script will repeat!!
  7. In the first time script, you will need to add a script to 'add to inventory'. Then add the object to inventory.
  8. Also to add to the First Time script above, you will want to add a 'Set Variable' script.
  9. In this set variable box, type this --> objectA.ItemsCollected
  10. Make sure the drop down box is clicked to expression.
  11. In the last box here next to expression, type this --> objectA.ItemsCollected - 1
  12. Do this for each of the objects the player needs to collect to end the game.
  13. Go back to the changedItemsCollected attribute on 'objectA' from step 3b.
  14. OPTIONAL: If you want, add a print message script here and change it to expression. Type something like the following in the box --> "The still need to collect this many items: " + jigsaw puzzle.MissingPieceCount --> this will print a message telling how many objects still need to be found.
  15. Add an If script here as well. Select object attribute equals from the options. In the next box select 'object'. In the next box select 'objectA'. In the attribute box type in --> ItemsCollected and in the ='s box type in --> 0
  16. For the then script, you can run whatever scripts you want to end the game.
  17. OPTIONAL: Add the same stuff above (#14) but add it to the 'Else If' section of this if script. Except, change the 0 (ZERO) above to a 1 and a 2 and a 3 for however many else if scripts you want to add. You can choose to print messages here letting the player know how awesome they are for finding another item! Print message "You have found another piece! Well done! There can't be too many left!"

Let me know if you have questions.


That seems quite a complex way to go about it.

I'd likely add an attribute to all the pieces. For example an attribute with the name "collection" and the value "jigsaw pieces"; or whatever they are. Or just a boolean.
Then a turn script looking something like:

if (ListCount(FilterByAttribute(ScopeInventory(), "collection", "jigsaw pieces")) = 6) {
  msg ("Congratulations, you found all 6 jigsaw pieces!")
  finish()
}

(or if you don't want to explicitly specify the number of pieces, you could use if (ListCount(FilterByAttribute(ListExclude(AllObjects(), ScopeInventory()), "collection", "jigsaw pieces")) > 0))


J_J

Doctor Agan already posted some great links, so not sure if you need more... but if all you need is the player to be carrying all the objects you can just use a simple if script. Essentially: if player is carrying object, object, and object, end game. To do this in the editor just pick the if script , and then choose "expression" and type in (Got(objectname) and Got(otherobjectname))

Here is what it would look like attached to a room exit (as in exiting any room carrying all the objects triggers the end game.)

    <inherit name="editor_room" />
    <onexit type="script">
      if ((Got(mouse) and Got(sunflowers))) {
        finish
        msg ("You have found all objects. The game is over.")
      }
    </onexit>

(ListCount(FilterByAttribute(ListExclude(AllObjects(), ScopeInventory()), "collection", "jigsaw pieces")) > 0))

That stuff makes no sense to me. I'm sure it is easier but I am uncomfortable with that type of code. Probably because I learned it that way when I started and that's what I can do. =)

Anyway, I'll fiddle with this when I get a chance.

Can you use something like this if it is NOT an inventory object? I use this method when certain things get achieved during a game. Does that make sense?


I got used to using functions to scan the inventory, to avoid different variables being out of sync with each other. If the player has to be carrying five items, then any other script that could move one of those objects around (a pickpocket stealing stuff from the player? a shop?) would need to update the count variable.

In this case, it's looking to see if you have all the puzzle pieces.

  • ListExclude (AllObjects(), ScopeInventory()) gives you a list of all the objects that are not in the player's inventory.
  • FilterByAttribute(ListExclude (AllObjects(), ScopeInventory()), "collection", "jigsaw pieces") filters the list down to just the ones that are jigsaw pieces
  • So ListCount(FilterByAttribute(ListExclude(AllObjects(), ScopeInventory()), "collection", "jigsaw pieces")) = 0 checks if there are zero pieces you haven't got. "Player has all the jigsaw pieces" and "There are no jigsaw pieces outside your inventory" are likely to be the same condition.

Keeping a variable to count the things you've done is a good method, but increases in complexity the more ways there are to accomplish the goal. If you're looking at a game where the items you need might be found, bought, or crafted, you end up having to add code to adjust your variable in every case, which makes it easier to miss something.

So where possible, I try to have collect quests evaluated by checking if the items are in your inventory, rather than maintaining a separate variable to track them. Whether that's using an attribute to identify the items for a particular quest, or just if (Got(vase) and Got(fish heads) and Got(magic sword)).


Thanks for the help y'all. I'll try some of these to see which one works.


ah, that is a cool code!

@ XanMag:

if I understand it myself, lol....

you're checking every Object in the game (but EX-cluding within your inventory), seeing if any of the required Objects are still needed (if they're found, they're not in your inventory, and thus you still need to find/get/take that item, before you can satisfy your requirement).

aka (this might be worded better): instead of checking your inventory if you have all of the needed items, you're checking outside of your inventory (checking the otherwise entire game), because if you don't have yet any of the needed items: if a needed item still exists outside of your inventory, then you're missing that item, and thus have to find/get/take that item, before you can complete your requirement of needed all of the required items.

does this makes sense in what it is doing? the code is still a bit hard to follow (though mrangel breaks it down for you), but this is what it is doing.


I totally understand what the goal of the code is. That was never really the question. My issue is the lack of comfort I have CREATING that code. Is that even possible through the GUI or is knowledge of code required for that.

I'm still buggered by all the ()'<"&/ symbols... and no, that is not intended to replace foul language although it most certainly would be appropriate! =)

I have a lot of respect for those of you who can work well in code. I am definitely NOT one of them but am learning... at a glacial speed.


(filler for getting my edited post, updated/posted)


I have the same difficulty with all of the other symbols (&xxx^ and etc) used in code, such as with the html/xml and the regex stuff, laughs.

It just takes awhile getting used to them... not easy... it's kinda like just remembering stuff, like for a biology test... the more you do it... the slowly it starts to become 'muscle-memory'...


well, understanding what the code is doing, is the first battle, so that's good you already got this, but the other half of the battle is understanding the code itself, being able to create/craft your own code, which is not easy, took me many years, since I found quest and started to try to learn to code from/with quest. Indeed, this is not an easy task.


this probably doesn't help much, but in general:

the parenthesis, '(xxx)', is used for either: 'conditions' (something you want to compare/check: 'if (conditions)', think of it as your science experiment itself and its hypothesis) or to pass in inputs/data, to be used by the scripting.

the curly braces, '{ xxx }', are used for what (separate: nothing to do with the "science-experiment / hypothesis") action(s) (aka, the scripting) you want done, based upon your 'hypothesis/science-experiment' (the parenthesis stuff) be successful and/or not.

the tags, '<xxx>xxx</xxx>' or '<xxx />', are the "physical/tangible things" (non-scripting: known in quest as: Elements), such as, an Object, a Function, an Exit, a Command, a Verb, a Turnscript, a Timer, an Attribute, etc etc etc.

examples...

<ELEMENT_TYPE NAME="xxx" optional_other_special_parameters>
  // content/body: Attributes, Objects, and/or scripting --- depends on the Element type
</ELEMENT_TYPE>

// just guessing at these... (I'm totally off... need to go into their actual code and study it... at some point):

<function name="if" parameters="condition">
  Eval (condition)
</function>

<function name="msg" type="string" parameters="message">
  return (message)
</function>

<function name="MoveObject" parameters="object_1, object_2">
  object_1.parent = object_2
</function>

// scripting (using the functions or attribute creation/alteration/usage or whatever else):

if (orc.dead) {
  msg ("The orc is dead")
} else {
  msg ("The orc is alive")
}

MoveObject (player, room99)

msg ("hi")

the 'if', 'MoveObject', and 'msg' are all built-in Functions/Scripts

//-----------

VARIABLE (as an Attribute or a Variable) = VALUE_OR_EXPRESSION

handled = false
count = 0
modifier = GetAttribute (player.weapon, "damage") * my_critical_hit_function

player.strength = 100
player.weapon = katana
katana.damage = 50
player.damage = player.weapon.damage * player.strength / 100

(ListCount(FilterByAttribute(ListExclude(AllObjects(), ScopeInventory()), "collection", "jigsaw pieces")) > 0))

That stuff makes no sense to me. I'm sure it is easier but I am uncomfortable with that type of code. Probably because I learned it that way when I started and that's what I can do. =)

So do it one step at a time

listcarried = ScopeInventory()
listnotcarried = ListExclude(AllObjects(), listcarried)
listnotcarriedandrequired = FilterByAttribute(listnotcarried , "collection", "jigsaw pieces")
count = ListCount(listnotcarriedandrequired)
if (count > 0)) {
   ...

It does the same thing, but spread over several lines so you can see what is going on at each stage.


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

Support

Forums