calling script on every exit, instead of specific exits (solved-ish for now)

Hey everyone, I just downloaded Quest, like, 2 days ago, and I'm writing an open-ended RPG adventure type game. As such, there will be skill check type rolls to pick locked doors/chests if you don't want to use the proper key.

I'm using the desktop version, I am not working w/ the code directly but instead using the visual interface (it's been a long time since I've looked at any code, so it's going to be a few weeks before I'm back up to speed on that front).

I have a fledgling idea of how to write this formula, and have tested it so I know it works. The question is can I have the script written in one place, like on a player or in game, instead of on each exit? If so, where do I put it, and how would I call the attribute off of the exit in question?



There's two ways I can think of to do this.

First is, select the Player object, and look at their Attributes. One of them is a script-attribute called 'changedparent'. It's attached to the other Player attribute 'parent', which is always the current room it's in. The script of changedparent is called ANYTIME parent itself changes.

Normally it can't be edited, but there is the Make Editable Copy to get around that. Do something like,

Player.changedparent = msg("We went to the new room, Mr. "+this.alias+"!")

And there you go.

Another way - the one I'd go for in your shoes - is if you want your code to happen for ALMOST all exits, but not precisely all of them, or if you don't want it to happen when you just use the script to move the player directly without using an exit.

I assume you know how to make exits call script instead of default moving. What you can do is instead create a new function (Also assuming you know how to make functions with and without parameters) and call it, I don't know, ExitMovingRolls for example. And you put the code in there and simply stick an 'ExitMovingRolls' onto each and every exit you want the special code for, and leave the others alone. If you ever need to modify the code, you just need to edit ExitMovingRolls itself instead of every single exit with the code.

So the way you recommend it is to write a new function, utilizing basically what I'm doing for the specific exit, and just make it a general-purpose version. Then, attach that function to each exit that needs it.

Correct? If so that sounds really easy to do.

If I do so, and I need to call variables for the exit or the room the exit is leaving, would I use "parent.attribute"? What about the room they go into? "to.attribute"?


Correct, except you don't need to make it general-purpose! Remember, attributes!

Give your ExitMovingRolls the parameter 'GivenExit', for example. In the code itself you can have a switch block, to decide what to do depending on which exit triggers it. In psuedocode:

GivenExit Attribute
switch (GivenExit)
case 'ExitLeadingToTrapDoor'{
//Do a bunch of rolls to avoid the trap door
case 'ExitLeadingToTreasureChest'{
//Do a bunch of rolls to determine the quality of the treasure you find

And in the exit itself, you call the function with the parameter of that object itself:

Move Based on Script (Not Default):
Call function ExitMovingRolls(With parameter 'this')

This will cause the code INSIDE ExitMovingRolls to treat 'GivenExit' as the exit itself (The variable 'this' is self-referential to the object itself).

If I do so, and I need to call variables for the exit or the room the exit is leaving, would I use "parent.attribute"? What about the room they go into? "to.attribute"?

No no, not at all!

Say we have the Player object. You need to get the player's parent attribute. In code, that's just:


And nothing more. An exit's destination is

If you have the Health attribute on the player, you can change it like so:

Player.Health = SomeNewNumber

You can even NEST attributes if you have an Object attribute, and you can get very creative then. For my current game I used it for the battle sequence. Like, the player has attribute Target, and OrcEnemy1 has attribute Health.

Player.Target = OrcEnemy1
Player.OutgoingDamage = 50
Player.Target.Health = Player.Target.Health - Player.OutgoingDamage (Reduces OrcEnemy1's health by 50)

Hope all this helps!

It does, thanks!

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