Some script help needed

Carrot
06 Jun 2013, 22:23
Hi.

I have dabbled with quest in the past, and am currently playing with the chrome extension.

I have a couple of scripting questions though.

Firstly, I would like to be able to create a random dungeon.

I will have a list of rooms to choose from, once visited they will not be able to be re-visited. Some rooms will only become available once a certain room has been visited.

Secondly, I want to do a multi switch puzzle

Each switch sets a flag

Switch 1
If all = 0, then A = 1
If A, B, C or D = 1, then ALL= 0

Switch 2
If A = 1 & B = 0, then B=1
If B, C or D = 1, then ALL = 0

Switch 3
If A & B = 1, then C = 1
If C = 1 OR A or B = 0, then ALL -0

And so on - thus requiring a perfect sequence of switch steps to unlock the puzzle

HegemonKhan
07 Jun 2013, 00:14
HK Edit: final version for~of this post (lol)

Carrot wrote:Firstly, I would like to be able to create a random dungeon.

I will have a list of rooms to choose from, once visited they will not be able to be re-visited. Some rooms will only become available once a certain room has been visited.


here's an example, you'll need to apply it though to your own game:

If you want or need to use lists or dictionaries (such as if you have a huge number of rooms, in which case, the list or dictionary usage would save you probably some time and~or at least better organization), then I'd have to nearly completely redo the coding for that, so let me know, if you want or need to use lists or dictionaries, and I'll write the code for it for you.

<object name="room_1">
<inherited name="room_object_type">
</object>

<object name="room_2">
<inherited name="room_object_type">
</object>

<object name="room_3">
<inherited name="room_object_type">
</object>

<type name="room_object_type">
<visited type="boolean">false</visited>
</type>

// place this script where ever you want~need it to be:

<random_room_selection type="script">
result=GetRandomInt(1,3)
switch (result) {
case ("1") {
if (room_1.visited=false) {
game.pov.parent=room_1
room_1.visited=true
} else if (room_1.visited=true) {
msg ("You've completed it already.")
}
}
case ("2") {
if (room_2.visited=false) {
if (room_1.visited=true) {
game.pov.parent=room_2
room_2.visited=true
} else if (room_1.visited=false) {
msg ("You haven't been to " + room_1.alias + "yet.")
}
} else if (room_2.visited=true) {
msg ("You've completed it already.")
}
}
case ("3") {
if (room_3.visited=false) {
if (room_2.visited=true) {
game.pov.parent=room_3
room_3.visited=true
} else if (room_2.visited=false) {
msg ("You haven't been to " + room_2.alias + "yet.")
}
} else if (room_3.visited=true) {
msg ("You've completed it already.")
}
}
}
</random_room_selection>

// You can probably use the "firsttime" script, instead of the visited=true/false and its object type structure, to make it much shorter

jaynabonne
07 Jun 2013, 00:30
Just a note: there already is a "visited" property, which is automatically set to true when the player has been in a room. So there's no need to set it yourself. But you can use it!

What I would do for the random room is to just have a list of rooms that can be visited. Then do a random selection into that list. Whatever room you select, remove it from the list so it won't be used again.

Carrot
09 Jun 2013, 09:54
Cheers, I'll play around with that.

Any help on the switch puzzle?

jaynabonne
09 Jun 2013, 12:56
For the switch puzzle, unless you definitely need a separate variable for each switch (e.g. an on/off state), I'd just have a variable (e.g. "index") which is the current state in the sequence. Start it out as 0. You'll need to put it somewhere - one place is the room. I'll assume the room is called "Room".

Switch A:
if (Room.index = 0) {
Room.index = 1
} else {
Room.index = 0
}


Switch B:
if (Room.index = 1) {
Room.index = 2
} else {
Room.index = 0
}


Switch C:
if (Room.index = 2) {
Room.index = 3
} else {
Room.index = 0
}


If you have the switches as separate objects, then you could have a common base type for all the switches. The only difference would be an attribute in each switch which tells at what point it's the next switch. Then you'd have a common script in the base type:

if (Room.index = this.index) {
Room.index = Room.index + 1
} else {
Room.index = 0
}


Then set Switch A index to 0, Switch B index to 1, Switch C index to 2, etc. (In some order). You could then even randomly assign the switch index variables if you want the switch order to be different each time.

Carrot
11 Jun 2013, 13:35
Cheers.