tutorial: defibrillator

lelo14
23 Sept 2011, 04:15
Okay I've worked my wat to this point in the tutorial

Intermediate
#4 More things to do with objects
#3 Using the defibrillator

I completely finished the section on using the defibrillator.

This is how the game is behaving now:

You are in a lounge.
You can see a TV, a sofa, a table, a lamp, a newspaper, a defibrillator and Bob.
You can go south.
This is quite a plain lounge with an old beige carpet and peeling wallpaper.

> look at bob
Bob is lying on the floor, a lot more still than usual.

> use defibrillator on bob
Miraculously, the defibrillator lived up to its promise, and Bob is now alive again. He says his head feels kind of fuzzy.

> look at bob
Bob is sitting up, appearing to feel somewhat under the weather.

> use defibrillator on bob
WHAT!?! You don't want to do that! Bob is alive! Using the defibrillator on a living person could kill them.



And from now on if you "use defibrillator on bob" you will get the same message.
I would like it if after the first warning, it would let you use it anyway and that will kill bob.
I assume there must be a way to count how many times someone tried to do something and cause a diffrent result once a threshold is met. but .... where to I find the documentation that tells me how to do that?


Thanks. lelo

P.S. my siggy is not working, anybody know what might be the problem?

Pertex
23 Sept 2011, 06:47
Then you have to do some scripting. First you need a variable or attribute, something like "alive", Then you must add the key defibrillator to the use-command of Bob and add a script. Something like this


<object name="bob">
<inherit name="editor_object" />
<inherit name="maleobject" />
<alive type="boolean">false</alive>
<useon type="scriptdictionary">
<item key="defibrillator">
if (bob.alive) {
msg("WHAT!?! You don't want to do that! Bob is alive! Using the defibrillator on a living person could kill them.")
} else {
bob.alive=true
msg("Miraculously, the defibrillator lived up to its promise, and Bob is now alive again. He says his head feels kind of fuzzy.")
}
</item>
</useon>

</object>


The Pixie
23 Sept 2011, 07:09
Pertex, I do not think that that is quite what he means.

Lelo14

Try this:
<object name="bob">
<inherit name="editor_object" />
<inherit name="maleobject" />
<warning type="boolean">false</alive>
<alive type="boolean">false</alive>
<useon type="scriptdictionary">
<item key="defibrillator">
if (bob.alive) {
if (bob.warning) {
SetObjectFlagOff(bob, "alive")
msg("Despite his struggling, you use the defibrillator on Bob, and he falls over dead.")
}
else {
SetObjectFlagOn(bob, "warning")
msg("WHAT!?! You don't want to do that! Bob is alive! Using the defibrillator on a living person could kill them.")
}
else {
SetObjectFlagOn(bob, "alive")
msg("Miraculously, the defibrillator lived up to its promise, and Bob is now alive again. He says his head feels kind of fuzzy.")
}
</item>
</useon>
</object>

I have added a new boolean, "warning", on Bob. If Bob is alive, it checks if the warning has been given, if so, you can kill him, if not, it gives the warning and and turns "warning" to true.

You can do this from the GUI, but it gets a bit tricky if you nested if...else, and it is a lot easier to show you the code than a dialogue box on here.

You mention counting to a threshold. It is not necessary in this case, but I will show you that too (say you want to give two warnings):
<object name="bob">
<inherit name="editor_object" />
<inherit name="maleobject" />
<count type="int">0</alive>
<alive type="boolean">false</alive>
<useon type="scriptdictionary">
<item key="defibrillator">
if (bob.alive) {
bob.count = bob.count + 1
if (bob.count > 2) {
SetObjectFlagOff(bob, "alive")
msg("Despite his struggling, you use the defibrillator on Bob, and he falls over dead.")
}
else {
msg("WHAT!?! You don't want to do that! Bob is alive! Using the defibrillator on a living person could kill them.")
}
else {
SetObjectFlagOn(bob, "alive")
msg("Miraculously, the defibrillator lived up to its promise, and Bob is now alive again. He says his head feels kind of fuzzy.")
}

</item>
</useon>
</object>

lelo14
23 Sept 2011, 07:12
Pertex wrote:Then you have to do some scripting. First you need a variable or attribute, something like "alive", Then you must add the key defibrillator to the use-command of Bob and add a script. Something like this


<object name="bob">
<inherit name="editor_object" />
<inherit name="maleobject" />
<alive type="boolean">false</alive>
<useon type="scriptdictionary">
<item key="defibrillator">
if (bob.alive) {
msg("WHAT!?! You don't want to do that! Bob is alive! Using the defibrillator on a living person could kill them.")
} else {
bob.alive=true
msg("Miraculously, the defibrillator lived up to its promise, and Bob is now alive again. He says his head feels kind of fuzzy.")
}
</item>
</useon>

</object>



Bob already has a flag called alive that can be true or false (per the instructions of the tutorial) I'm not sure how a flag is diffrent from a variable is diffrent from an attribute. I'm hoping the distinction of the three will become clear. But anyways, won't the flag be enough?

I also already have key defibrillator for the use-command of Bob which has a script that runs a function that revives bob. This is also per the instructions of the tutorial. I can add more stuff to that funtion.

If I was writing this in C, I would have a variable triedDefibb that would be initialized to 0, then if the user tried to use the defibrillator on bob when he was alive then if triedDefib was less than 2 you would get the old message and triedDefib would get incremented, otherwise if triedDefib was 2 then bob's alive flag would get set to false, triedDefib would get set to 0, and you would get a message saying, something like, You killed him!

I don't see where in your suggested script there is any counter for how many times the person tried to use the defib on bob when he was alive. I'm asking, how do you set up the counter? Is it an atribute? (of what object?) Is it a variable? In this system I haven't seen any variables. How would I create one and manage it?

Thanks - lelo

lelo14
23 Sept 2011, 07:23
Pixie, thanks so much, I'm going to go give it a try. I'll probably do it from the GUI for now until I get to the more advanced scripting lessons.

So would you make the count or warning "variable" an atribute of bob?

Thanks, lelo

P.S. I'm a girl.

The Pixie
23 Sept 2011, 08:37
I tend of think of the as attributes when in GUI and variables in the code view, but they are almost interchangeable (once you get into coding, you will find you can have local variables too, which are different, and attributes can be scripts too).

If you can translate the code I wrote into the GUI, then you are ready to code, I would say. The advantage of the GUI is that it is harder to miss out brackets and braces, and in a long game file, they can be a real pain to track down. You can also swap between code and GUi as you work. I often start in the GUI, then go into code when the if...else gets too complicated (though be aware that there is a bug Alex is working on that means Quest will hang every now and again as you go from code to GUI; fortunately, it always saves first, so you will not lose anything).

Pertex
23 Sept 2011, 08:59
You can use a variable within a script, something like


var1="test"
var2=2


but if the script is ended, the variables are lost

With attributes you can save values permanently. You can add an attribute to every object you want. In my game I have a special object, where I save all my attributes, something like this:


<object name="vars">
<PersonPatrickStatus type="int">0</PersonPatrickStatus>
<PersonKennethStatus type="int">0</PersonKennethStatus>
<Spielername type="string"></Spielername>
<Spielervorname type="string"></Spielervorname>
<Spielergeschlecht type="string"></Spielergeschlecht>
</object>



So I can call this attributes from all over the game with "vars.attributename"

lelo14
23 Sept 2011, 16:58
Thanks Pertex and Pixie,

I learned a lot more than I expected.
So far, I haven't seen how to switch from GUI to code......

Okay, I found code view.
It was long (and so far I just have my tiny tutorial with two rooms).
Is all the code for the entire game in one file?
When it gets really hugh, how do you find the section you want to work on?

What is the diffrence between a scripting language and a programing language?
What language are we using here? Is it Quest specific?
If it is Quest specific, what common language is it most like?
Where can I find the syntax rules?

Does the tutorial cover accessing and using the code view?

Thanks again. lelo

P.S. my siggy is still not showing up, not that it matters but it's annoying.

Alex
23 Sept 2011, 17:12
All your game code is in one file, but you could split it up by creating libraries if you wanted.

There's no real difference between a "scripting" language and a "programming" language - but generally "lightweight" languages (like Quest's) are referred to as scripting languages, as you wouldn't be likely to write a word processor in Quest, for example.

Quest's language is called ASL which stands for Adventure Scripting Language. It's similar in structure to C#, although expressions more closely resemble VB. All the documentation is on the wiki at http://quest5.net

The tutorial doesn't cover code view... unless anybody wants to write a section about it...

Signatures are turned off on this forum.

lelo14
23 Sept 2011, 21:30
Okay, I got bold and tried to edit the code because I wanted to do the treshold thing and I could not figure out how to do it from the GUI. But now I can't open my Tutorial Game for play or edit and I get an error message saying that

Error launching game: Missing '}'

Because I can't open it to edit, it I can't fix my missing '}' so ..... ARGH! What do I do?

Is it really the case that I can't do the treshhold thing from the GUI? It really seems like I should be able to give the defibulator an attribute defibWarning that is initalized to 0 and gets incremented for warnings and reset to 0 but I can't find a place in the GUI that lets me change the value of the darn atribute. Which makes me feel dumb because there seems like there really should be a way.

The Pixie
23 Sept 2011, 22:04
You can open the game up in notepad or wordpad to edit it.

Now I look at it, I think I missed a } - try this instead:
<object name="bob">
<inherit name="editor_object" />
<inherit name="maleobject" />
<warning type="boolean">false</alive>
<alive type="boolean">false</alive>
<useon type="scriptdictionary">
<item key="defibrillator">
if (bob.alive) {
if (bob.warning) {
SetObjectFlagOff(bob, "alive")
msg("Despite his struggling, you use the defibrillator on Bob, and he falls over dead.")
}
else {
SetObjectFlagOn(bob, "warning")
msg("WHAT!?! You don't want to do that! Bob is alive! Using the defibrillator on a living person could kill them.")
}
}
else {
SetObjectFlagOn(bob, "alive")
msg("Miraculously, the defibrillator lived up to its promise, and Bob is now alive again. He says his head feels kind of fuzzy.")
}
</item>
</useon>
</object>

There is an extra line with just a } on it that I missed. Sorry about that.

Anything you can do in the code view you can also do in the GUI and vice versa. To change the value of a variable in the GUI, select "Variables - set a variable or attribute". If you are not sure how to do something in the GUI, do it in code, then go to the GUI and see how it is displayed.

lelo14
24 Sept 2011, 00:22
Pixie, thanks so very much!!!

It's fixed!
It works just the way I want it to.
I totally understand why so I can do something similar in the future.
I learned so much!

Thanks,

lelo

P.S. I wasn't your curly brace that caused the problem;
I didn't copy and paste.
So it was my own dumb fault that I left out a brace.

Jimmy Janiform
24 Sept 2011, 20:26
I guess it's easier to make more objects. number 1 brings him back to life, but afterwards it disappears. The player won't get to see this though, because at the same moment you make number 2 disappear. This one gives you a warning and afterwards number 3 appears and 2 gets hidden. The 3rd one will be able to kill Bob.

It's what I always do and much simpler if you ask me.

lelo14
25 Sept 2011, 15:49
Jimmy Janiform wrote:I guess it's easier to make more objects. number 1 brings him back to life, but afterwards it disappears. The player won't get to see this though, because at the same moment you make number 2 disappear. This one gives you a warning and afterwards number 3 appears and 2 gets hidden. The 3rd one will be able to kill Bob.

It's what I always do and much simpler if you ask me.


I see how that would work. I'm not sure that it would result in the most efficent program (fewest cpu cycles and minimum memory used) nor the most readable code. Two things which I highly value.

But it's a trick to keep in mind. Swap out on the sly one object for another that the user thinks are the same object when in fact it is diffrent wth diffrent behaviour/properties etc instead on dynaamically changing the behavior/properites on the first object.

The Pixie
25 Sept 2011, 20:10
If I was doing this, I would have the dead guy as one object, and him alive as another object. Things like speakto and ask/tell are specific to the alive version. Iy you have two different objects and you do not have to test whether he is alive or dead in the responses.