How to require multiple objects

erinlogan
11 Oct 2017, 20:39

How do I make something require the player to have multiple objects? For example, you have to turn on the object remote but in order to turn it on, the player must have picked up all 3 batteries?


mrangel
11 Oct 2017, 21:16

It depends on how those objects are set up.

If there's only 3 batteries in the game, then you could have something like
if (Got(battery 1) and Got(battery 2) and Got(battery 3)) {
in your code.

If there's more than 3 batteries and you need at least three of them, it becomes a bit more complicated. I can go into that if the above solution doesn't work for you.


hegemonkhan
12 Oct 2017, 00:56

just a small correction to mrangel's code:

the 'Got' Function/Script checks if the Object is contained within the 'player' Object

(so, you'll have to be able to 'take' each battery object, and have all 3 of them in your: inventory === contained within your 'player' Player Object, at the same time, for it to do the scripting)

(there is no 'Has' Function/Script, unless this is something Pixie added into a quest update)

if (Got (battery 1) and Got (battery 2) and Got (battery 3)) {
  // scripting
}

your choices of methods/designs, depend upon your game design setup, but mrangel is showing the simplest method/design for the simplest game design setup

if you want/have a more complex game design and/or want a more complex method/design, then let us know.


Doctor Agon
12 Oct 2017, 00:57

The complication would arise if you had more than 3 batteries. eg:

if (Got(battery 1) and Got(battery 3) and Got(battery 4)) or (Got(battery 1) and Got(battery 2) and Got(battery 5)) or (Got(battery 4) and ...

You get the idea.
A simpler solution would be to have an attribute on the battery, so that when you picked the battery up, it added one(1) to the battery count. All you would then do is check for that:

If battery.count=3 then ...

Sorry about the code writing on the fly


mrangel
12 Oct 2017, 08:27

Using a variable to count how many items you have is one way to do it :)

I'd probably give the batteries an attribute "item_type" and set it to "battery". Then to check how many the player has:

batteries_found = FilterByAttribute(ScopeInventory(), "item_type", "battery")
if (ListCount(batteries_found) < 3) {
  msg ("You try to turn it on, but you don't have enough batteries.")
}
else {
  // code to turn it on goes here
}