Script after defined number of turns

steve the gaming guy
08 Jun 2005, 16:42
I wasn't exactly sure what to call this post so hopefully what I decided will do.

I've searched the forum and I can't find a related topic. During a game, if I wanted to have the player take a certain number of turns before something else happens, how would I go about it?
For example:
The player walks into a room and after, let's say, 2 commands (regardless of the commands), the floor begins to shake.

Would that be an AfterTurn command for that particular room? Or would I have to create a variable of some sort?

francisstokes
08 Jun 2005, 18:06
ok heres what id do.

make a variable called turn_counter or similar....doesnt really matter.
then after each turn in the room increment the turn_counter variable by 1.
Then, also in the "after each turn" section, make an if statement that checks if the turn counter is equal to 2, and if it is, put all the required script into the "then" box.

That should do it.

paul_one
08 Jun 2005, 19:02
Use properties...
Much easier to keep track of as they're organised... Variables are not organised so well.
*talking about the debug menu here - something everyone SHOULD use to de-bug a game and keep track of stuff!*

steve the gaming guy
08 Jun 2005, 20:41
francisstokes, I see what you're saying. I'll give that a try.

Tr0n, that was kind of a general idea. I'm not sure what to do with properties. In other words, I don't know how to make properties work in that manner. Could you give me a brief example?

paul_one
08 Jun 2005, 21:40
Say you have a property "movesmade" (mmade or mm for a short, easy to type-out name)... Then you would have:

afterturn {
inc <#(quest.currentroom):mmade#>
if <#(quest.currentroom):mmade# = 2> then {
' DO ACTION!
}
}

in the room's afterturn bit.
Thing is, you can then really easily turn this into a generalised procedure you can use throughout multiple games that you can make up quickly, you can even have rooms doing different things after a certain number of moves without having to mess about with a billion variables and trying to remember where each one is (or ugly names like %thearchbeforethechurchingreytown3moves%.

steve the gaming guy
09 Jun 2005, 14:21
very nice...I will definitely have to try that one out as well.

I tried your way, francisstokes, yesterday. That works good too.

steve the gaming guy
09 Jun 2005, 17:05
Here is a test code based on your idea, Tr0n. I can't get it to work right. Am I doing it wrong?
What I have below was created in QDK. In the game properties, I created the property "mm".
Within the room, I created the afterturn commands.

' "Sid Gentry"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Sid Gentry>
asl-version <350>
gametype singleplayer
start <start>
game author <Steve Lingle>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
properties <mm>

end define
end define

define synonyms
end define


define room <start>
alias <dark hallway>
look <In this hallway, the light is so dim that you cannot see more than a few feet in front of you.>
indescription <You are in a:>

afterturn {
inc <#(quest.currentroom):mm#>
if <#quest.currentroom:mm# = 2> then msg <You have successfully completed the test to make sure this type of property programming is working!>
}
end define

define text <intro>
end define

define text <win>
end define

define text <lose>
end define



Cryophile
09 Jun 2005, 17:18
You missed the second set of parenthesis on the 27th line of code.

MaDbRiT
09 Jun 2005, 19:20
Steve...

You've got a fundamental problem with the code given above, by declaring a property in the game block with

properties <mm>


what you've done is create a boolean (true/false) variable for the GAME object... The game has the property of "mm" and testing for it would return "true" if you prefer to think that way.

later in the room code you try and read 'mm' as if it were a property of the current room (which it isn't!) and of string type, which it also isn't!

I repeat - as written 'mm' is a property of the GAME not the ROOM and it of of the wrong type anyway. You also try to use the increment (inc) method on the property - which (AFAIK) isn't supported, it only works on numeric variables (and possibly arrays, I've not tried that for some reason).

For the simple reason that I can't find a way to make properties behave as anything other than boolean or string, I avoid their use completely when I'm trying to do anything involving counting. You can store numbers in them OK (I do it a lot in typelib) but you'll notice all the assignments and calculated values are done with numeric variables if you look at my code.

What I'd suggest here is a simple numeric variable initialised in the startscript and incremented/decremented in the afterturn of the appropriate room.

Al (MaDbRiT)

steve the gaming guy
09 Jun 2005, 19:29
Hey thanks for the help!

MaDbRiT
09 Jun 2005, 19:40
For Steve (again)

Just to prove my point as above - and demo how you CAN do this using properties (with a temporary numeric variable to accumulate the count), here's your code re-written so that it works:

' "Sid Gentry" 
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <Sid Gentry>
asl-version <350>
gametype singleplayer
start <start>
game author <Steve Lingle>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
end define

define synonyms
end define


define room <start>
alias <dark hallway>
look <In this hallway, the light is so dim that you cannot see more than a few feet in front of you.>
indescription <You are in a:>
properties <mm=0>
afterturn {
set numeric <tempValue;#(quest.currentroom):mm# +1>
property <#quest.currentroom#; mm=%tempValue%>
if (#(quest.currentroom):mm# =2 ) then msg <You have successfully completed the test to make sure this type of property programming is working!>
}
end define

define text <intro>
end define

define text <win>
end define

define text <lose>
end define


Notice how I've moved the mm property definition into the room definition - and made it a conventional not boolean type by assigning it a value. This means 'mm' IS now a property of the room and can be tested as such (as the fact the code above works, proves)

The other issue is the use of the numeric variable to accumulate the count which is then stored in the property. This is the way I work with 'numeric' properties as I described in previous posting.

Hope this helps

Al (MaDbRiT)

paul_one
09 Jun 2005, 21:33
True...
I just took the assumptions that inc would work - I stand corrected.
I usually do the same, but didn't like typing out a long reply and apologise for my shoddy reply.

francisstokes
10 Jun 2005, 06:38
I would still go with variables.
Because, although tron said you have to make millions of vars, you could just recycle 1 of them.Like this

' "test"
' Created with QDK 3.53 - UNREGISTERED VERSION

define game <test>
asl-version <350>
gametype singleplayer
start <test1>
game info <Created with QDK 3.53 - UNREGISTERED EVALUATION VERSION.>
define variable <recycling variable>
type numeric
value <0>
end define
end define

define synonyms
end define

define room <test1>
afterturn {
inc <recycling variable; 1>
if ( %recycling variable% = 2 ) then {
msg <this is the first time.>
goto <test2>
}
}
end define

define room <test2>
script {
set numeric <recycling variable; 0>
inc <recycling variable; 1>
if ( %recycling variable% = 2 ) then msg <This is the second time>
}
end define

define text <intro>

end define

define text <win>

end define

define text <lose>

end define



paul_one
10 Jun 2005, 08:40
That won't work - for obvious reasons.
It's better to have seperate variables - you may want to have a thing happen once, instead of over and over again... Alot easier to use one seperate property than one variable that need's re-setting and a flag (perhaps two or more flags!).

007bond
10 Jun 2005, 09:24
I believe I'm correct in saying that someone can just type in any old command and it will take a turn (regardless of whether or not it is valid). It would take some work, but it might be worth investing some time into checking each string the user types in.

steve the gaming guy
10 Jun 2005, 12:36
Using the code that MaDbRiT posted, I tested your theory. You are correct in that even invalid commands count as a turn.

apologise for my shoddy reply.



Tr0n, no problem.

paul_one
10 Jun 2005, 15:15
I think there's a built-in variable somewhere with a success/failure.

francisstokes
10 Jun 2005, 15:29
Whats are the obvious reasons?
If you have a variable specificaly for counting turns in different rooms, the script will still execute.

paul_one
10 Jun 2005, 19:32
What are the two errors with the following?

define room <test2>
script {
set numeric <recycling variable; 0>
inc <recycling variable; 1>
if ( %recycling variable% = 2 ) then msg <This is the second time>
}
end define



... One, it's in a script {} tag - meaning execute when they enter the room ONLY.
Two - it's all in ONE tag (script). So the variable will be reset before you test it. So it will NEVER equal 2.

...... Don't think your code is perfect - read others have written, EXPECT your code to be wrong, and then look through to correct it!

francisstokes
10 Jun 2005, 19:40
Didnt mean to do that :oops:.I meant to put it into the after turn box.

MaDbRiT
10 Jun 2005, 19:46
Steve wrote

Using the code that MaDbRiT posted, I tested your theory. You are correct in that even invalid commands count as a turn.



Well yes they do - because whatever the player types the parser attempts to make sense of and act upon - even if it is only to print 'I don't understand your command". Rightly (or wrongly depending on your point of view) the parser has evaluated the users input and so triggers the 'afterturn'.

I'm not aware of any way you can easily check that the parser has returned 'I don't understand' and thus cancel incrementing the count in the "fuse" variable. There may be a variable we can read (Alex?) to check this - but if there is I don't know what it is. :-)

Al (MaDbRiT)

steve the gaming guy
10 Jun 2005, 19:57
That might be interesting to find out but for my needs, counting bad commands works just fine.

paul_one
10 Jun 2005, 21:48
I am corrected again.
I was using a 'dont process' thingy last time I tried an afterturn event thingy, which did the job for me in the "before turn" part (checking for a valid command).