Returning the integer to zero

Silver
I've tried various variations on this code:

room.description = 0
\\in start script


\\room script
if (room.description = 4) {
room.description = room.description - 4
}
\\this is the bit i'm getting wrong. The code below works fine.
room description = room.description + 1
msg ("{if room.description=1:Wow, the code is right!}")


But no joy. I tried putting part two inside the curly braces but that didn't work either. What's wrong with my thinking here?

HegemonKhan
you simply (re)set it to zero:

// 'start' Script:
room.description = 0

// 'roomX' Script:
if (roomX.description = 4) {
-> roomX.description = 0
}
msg ("{if roomX.description=0:blah0}")
msg ("{if roomX.description=1:blah1}")
msg ("{if roomX.description=2:blah2}")
msg ("{if roomX.description=3:blah3}")
roomX.description = roomX.description + 1

~OR~

// roomX Script:
if (roomX.description = 4) {
-> roomX.description = 0
}
roomX.description = roomX.description + 1
msg ("{if roomX.description=1:blah1}")
msg ("{if roomX.description=2:blah2}")
msg ("{if roomX.description=3:blah3}")
msg ("{if roomX.description=4:blah4}")

~OR~

// 'start' Script:
room.description = 0

// example:
<function name="function1"><![CDATA[
-> if (roomX.description > 4) {
->-> roomX.description = 0
-> }
-> msg ("{if roomX.description=0:blah0}")
-> msg ("{if roomX.description=1:blah1}")
-> msg ("{if roomX.description=2:blah2}")
-> msg ("{if roomX.description=3:blah3}")
-> msg ("{if roomX.description=4:blah4}")
-> roomX.description = roomX.description + 1
]]></function>

~OR~

// 'start' Script:
room.description = 0

// example:
<function name="function1"><![CDATA[
-> if (roomX.description > 4) {
->-> roomX.description = 0
-> }
-> roomX.description = roomX.description + 1
-> msg ("{if roomX.description=1:blah1}")
-> msg ("{if roomX.description=2:blah2}")
-> msg ("{if roomX.description=3:blah3}")
-> msg ("{if roomX.description=4:blah4}")
]]></function>

~OR~

look up the 'modulus operator' (%):

http://en.wikipedia.org/wiki/Modulo_operation
https://msdn.microsoft.com/en-us/library/h6zfzfy7(v=vs.90).aspx


game.turns = 0

game.minutes = game.turns / 60
game.seconds = game.turns % 60
game.turns = game.turns + 1

game.turns = 0
game.minutes = 0
game.seconds = 0

game.turns = 1
game.minutes = 0
game.seconds = 1

game.turns = 59
game.minutes = 0
game.seconds = 59

game.turns = 60
game.minutes = 1
game.seconds = 0

game.turns = 61
game.minutes = 1
game.seconds = 1

game.turns = 119
game.minutes = 1
game.seconds = 59

game.turns = 120
game.minutes = 2
game.seconds = 0

game.turns = 121
game.minutes = 2
game.seconds = 1

-----

some links on modulus operator:

viewtopic.php?f=10&t=4569&p=30038&hilit=modulus#p30038

viewtopic.php?f=10&t=3937&p=26421&hilit=modulus#p26421 (good, but extensive):

// me (HK), trying to understand it (ie: remainder math), lol:
// turns % 60 = seconds
// 000 % 60 -> 000 / 60 = 0 -> 0 x 60 = 000 -> 000 - 000 = 00
// 001 % 60 -> 001 / 60 = 0 -> 0 x 60 = 000 -> 001 - 000 = 01
// 059 % 60 -> 059 / 60 = 0 -> 0 x 60 = 000 -> 059 - 000 = 59
// 060 % 60 -> 060 / 60 = 1 -> 1 x 60 = 060 -> 060 - 060 = 00
// 061 % 60 -> 061 / 60 = 1 -> 1 x 60 = 060 -> 061 - 060 = 01
// 119 % 60 -> 119 / 60 = 1 -> 1 x 60 = 060 -> 119 - 060 = 59
// 120 % 60 -> 120 / 60 = 2 -> 2 x 60 = 120 -> 120 - 120 = 00
// 121 % 60 -> 121 / 60 = 2 -> 2 x 60 = 120 -> 121 - 120 = 01

hope this helps, if not ask for help!

Silver
I was experimenting with returning strings on a rotational rather than random basis. I'll have a read on the modulus operator though. What does

->


mean?

Pertex
Be careful! 'description' is the internal variable for saving the room decription as string

HegemonKhan
just my own lazy way of showing the indenting (too lazy to put it into the code box, lol): as 'arrows', ->, ->->, ->->->, etc

(though Jay points out that it's annoying if~when someone wants to copy and paste it, as they got to manually go and remove all of my 'arrows', which I have found myself the victim of my own 'arrows' too, having to remove them when I wanted to copy and paste my own code... haha. Though, I still use these 'arrows' as they're a quick method of using when typing out code for these posts)

if (xxx1.xxx2 = xxx3) {
-> msg ("hi")
-> if (xxx4.xxx5 = xxx6) {
->-> msg ("bye")
-> }
}

represents this:

if (xxx1.xxx2 = xxx3) {
msg ("hi")
if (xxx4.xxx5 = xxx6) {
msg ("bye")
}
}


as otherwise, the post's formating causes the indenting (spaces) to be left out, as seen:

if (xxx1.xxx2 = xxx3) {
msg ("hi")
if (xxx4.xxx5 = xxx6) {
msg ("bye")
}

Silver
Oh.

so room.seen would be better?

jaynabonne
I'm not sure what you're trying to do, so I can't say exactly what's going wrong. As HK said, if you want it to be 0, then you can set it to 0.

There is a typo, though, in what you posted:

room description = room.description + 1

needs a dot after the first "room" (room.description).

As far as your code in general, the way you have it coded, then:

if room.description is 4, then it will be 1. Otherwise, it will be room.description+1.

As I said, I don't know what you're trying to do, so I can't say whether the code is doing it right or wrong!

(It also seems odd to me to be using "description" as an integer variable, since "description" is the name of the string or script attribute that Quest uses to display the room description. Which means that when the player comes into the room, Quest will just ignore it. Where does the script you showed exist? If it's the room description script, then as soon as you run your game, you set it to an integer 0 and lose the script!)

[Sorry, cross posted.]

Silver
Although it might not matter for me as it pertains to a redundant object that I created for somewhere to attach the attribute to rather than a room.

Silver
The room is decompression chamber. I created an object called compression solely for the purpose of the attribute so I haven't stumbled into that particular nightmare.

compression.description

Silver
I don't have the typo in the game but cheers for pointing it out.

Silver
jaynabonne wrote:I'm not sure what you're trying to do, so I can't say exactly what's going wrong. As HK said, if you want it to be 0, then you can set it to 0.

There is a typo, though, in what you posted:

room description = room.description + 1

needs a dot after the first "room" (room.description).

As far as your code in general, the way you have it coded, then:

if room.description is 4, then it will be 1. Otherwise, it will be room.description+1.

As I said, I don't know what you're trying to do, so I can't say whether the code is doing it right or wrong!

(It also seems odd to me to be using "description" as an integer variable, since "description" is the name of the string or script attribute that Quest uses to display the room description. Which means that when the player comes into the room, Quest will just ignore it. Where does the script you showed exist? If it's the room description script, then as soon as you run your game, you set it to an integer 0 and lose the script!)

[Sorry, cross posted.]


Basically on returning the room description the integer counts upwards from 1 but when it reaches 4 that should be 1 again.

The Pixie
Based on what you describe, I implemented this myself, and it works fine.
<!--Saved by Quest 5.5.5328.26617-->
<asl version="550">
<include ref="English.aslx" />
<include ref="Core.aslx" />
<game name="count">
<gameid>2e12d5bd-b5e8-4bd4-bbcc-b184f570b340</gameid>
<version>1.0</version>
<firstpublished>2015</firstpublished>
<start type="script">
decompression.description = 0
</start>
</game>
<object name="room">
<inherit name="editor_room" />
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
</object>
<exit alias="south" to="decompression chamber">
<inherit name="southdirection" />
</exit>
</object>
<object name="decompression chamber">
<inherit name="editor_room" />
<description type="script">
if (decompression.description = 4) {
decompression.description = decompression.description - 4
}
// this is the bit i'm getting wrong. The code below works fine.
decompression.description = decompression.description + 1
msg ("{if decompression.description=1:Wow, the code is right!}")
</description>
<object name="decompression">
<inherit name="editor_object" />
<scenery />
</object>
</object>
</asl>

Silver
No idea why it hasn't worked for me then. :D it was late though. Will put fresh eyes on it later.

Silver
Although I've no idea what all that inherit stuff is doing.

The Pixie
The inherit is what gives a thing its type. In that simple game, it sets some things to be objects and others to be rooms, so the editor displays different tabs for them. If you set an object to be a container, it will inherit the container type too (and in that case, it will affect how it works when played; editor_room and editor_object are not used during play at all).

Silver
Oh, then I guess Quest does that for me anyway when I create the rooms/objects. For clarity, my script worked counting 1-3 but just didn't go back to 1 again. I'll have another look later.

HegemonKhan
the placement-order of your code lines matter, depending on your entire scripting (your script block~s), so depending on your script block(s), you'll need to place your 'decompression.description = decompression.description + 1' in the right placement-order in your script block~s (your scripting).

otherwise, maybe you just have a simple typo-like mistake somewhere in your code.

see (from my previous post for an example of) this, here:

// 'start' Script:
room.description = 0

// 'roomX' Script:
if (roomX.description = 4) {
-> roomX.description = 0
}
msg ("{if roomX.description=0:blah0}")
msg ("{if roomX.description=1:blah1}")
msg ("{if roomX.description=2:blah2}")
msg ("{if roomX.description=3:blah3}")
roomX.description = roomX.description + 1

~OR~

// roomX Script:
if (roomX.description = 4) {
-> roomX.description = 0
}
roomX.description = roomX.description + 1
msg ("{if roomX.description=1:blah1}")
msg ("{if roomX.description=2:blah2}")
msg ("{if roomX.description=3:blah3}")
msg ("{if roomX.description=4:blah4}")

~OR~

// 'start' Script:
room.description = 0

// example:
<function name="function1"><![CDATA[
-> if (roomX.description > 4) {
->-> roomX.description = 0
-> }
-> msg ("{if roomX.description=0:blah0}")
-> msg ("{if roomX.description=1:blah1}")
-> msg ("{if roomX.description=2:blah2}")
-> msg ("{if roomX.description=3:blah3}")
-> msg ("{if roomX.description=4:blah4}")
-> roomX.description = roomX.description + 1
]]></function>

~OR~

// 'start' Script:
room.description = 0

// example:
<function name="function1"><![CDATA[
-> if (roomX.description > 4) {
->-> roomX.description = 0
-> }
-> roomX.description = roomX.description + 1
-> msg ("{if roomX.description=1:blah1}")
-> msg ("{if roomX.description=2:blah2}")
-> msg ("{if roomX.description=3:blah3}")
-> msg ("{if roomX.description=4:blah4}")
]]></function>

Silver
I did remember some guy said recently about the script triggering at the same time. If the script is telling the integer to return to zero at the same time it's telling it to add one etc. But surely the engine reads it sequentially?

The Pixie reckons he's had it working though so I'm going with a typo being the cause. although:

if (compression.description = 4) {
compression.description = 0
}
compression.description = compression.description + 1


To me, seems tidier code than what I was doing:

if (compression.description = 4) {
compression.description = compression.description - 4
}
compression.description = compression.description + 1

HegemonKhan
well, those are really the same thing:

0 (HK) = VS = 4 - 4 (Silver)
0 + 1 = 1 (=VS=) 4 - 4 + 1 = 1

lol :D

Silver
Yeah. But less typing. :P

HegemonKhan
yep, though you're thinking good in what you did, though in this case, it's over-thinking, as you can just do:

decompression.description = 0

instead of:

decompression.description = decompression.description (4) - 4 (= 0)

what you did though is good, when you don't want a specific result (such as in your case: 0~zero), such as with this:

(err, really bad~illogical example, lol ~ this is the best I could think of in the moment, laughs)

if (player.age => 24) {
player.age = player.age - 4
if (player.age = 20) {
msg ("You're now 20, 4 years younger, than you were at 24")
} else if player.age = 21) {
msg ("You're now 21, 4 years younger, than you were at 25")
} else if (player.age = 22) { // etc etc etc
}
}

jaynabonne

I did remember some guy said recently about the script triggering at the same time. If the script is telling the integer to return to zero at the same time it's telling it to add one etc. But surely the engine reads it sequentially?



That poster was a little confused. It had to do with certain UI operations not blocking, not with the actual sequential execution of code.

HegemonKhan
anything that causes a popup window (like show menu) or a clicking~typing command (like wait or get input), can't be run at the same time as another such thing, so you got to be creative with your scripting ordering or design... to avoid this complication that quest~computers~coding can't handle.

(for example if you got a fighting game that requires you to press 3 keys on your keyboard at the same time to do a move, and pretend that you, well for me anyways I can't do this ~ lol, can time the pressing of the 3 keys to being at the same time, it won't work, as the computer can only handle 2 keyboard keys being pressed at the same time. you'll have to have a program to assign 3 buttons~keys to just being a single button~key, to do such a move with the keyboard).

--------

however, the placement-order of your code lines, do matter. there's a big difference between:

game.turns = 0

game.turns = game.turns + 1
if (game.turns = 0) {
-> msg ("hi") // this will never be output'ed, as game.turns = 0 gets skipped due to 'game.turns = game.turns +1' happening first
} else if (game.turns = 4) {
-> game.turns = 0
}

and (VS):

game.turns = 0

if (game.turns = 0) {
-> msg ("hi")
} else if (game.turns = 4) {
-> game.turns = 0
}
game.turns = game.turns + 1

just plug in numbers, testing your scripting (script block~s), to see the difference.

Silver
jaynabonne wrote:

I did remember some guy said recently about the script triggering at the same time. If the script is telling the integer to return to zero at the same time it's telling it to add one etc. But surely the engine reads it sequentially?



That poster was a little confused. It had to do with certain UI operations not blocking, not with the actual sequential execution of code.



Interesting thread though. Me finally starting to use functions was the outcome for me. No idea why I was avoiding them. In fact I'd created a lot of needless work by avoiding them.

HegemonKhan
Sometimes, you do want the scripting to be directly inside of the Object's Script Attribute (Verb) or a Command or Turnscript or other ELEMENTS, but usually having the scripting being inside of Functions is best, especially for organization, and their 'ease of use' in putting them into what~where ever you want them to be used, and in~with reducing redundency (less typing).

Just wait until you start using the Function's 'Parameters' and 'Return' features too, hehe :D

and then we'll both have to learn this more advanced 'regex' stuff (scripts with same and better features than Functions, if I understand correctly), though Jay says that he doesn't use them too much, meh.

Silver
Ah yeah, funny you should mention it... :lol:

What are the parameters and what do they do?

Silver
Although I'm just curious really. I'm learning stuff on a need-to-know basis. Although the more I learn, I realise I needed to know it much earlier than I thought. :lol:

That's why I'm pleased I haven't galloped ahead with my game. It would have been a nightmare I think.

jaynabonne
Actually, regex (regular expressions) are just a more advanced pattern matcher for commands in Quest. They're also used a lot outside Quest, but as far as I know, you only use them in Quest for commands.

Generally speaking, Parameters are how you pass values into a function, and the return value is how you pass a value back out. For example, if you have a function like this:

<function name="Addem" parameters="a,b"  type="int">
return(a + b)
</function>

then "a" and "b" represent two values coming in, and the function returns an integer value. You could do:

result = Addem(3, 5)


and result would be 8. Of course, that's a trivial example, but it shows the various pieces.

HegemonKhan
this is a bit complicated to explain, and I'm not good at explaining... lol. I'll try, but you may need to wait for Jay's or Pixie's post to better understand Parameters, as they can explain stuff very well, unlike me.

Parameters are a way of 'getting' and (if you want to) temporarily 're-labeling' those things gotten, for using in your Functions.

for examples (this might work best for me in trying to explain):

'start' Script:
character_creation_function (player)
// the Parameter '(player)', is getting the 'player' Object to use in the Function 'character_creation_function'

character_creation_function:

<function name="character_creation_function" parameters="x">
// I'm lazy, and I don't want to write out 'player' lol, so instead I've (temporarily) changed the label of 'player' ( 'alias' String Attribute: quasi-permanent) to 'x' (a temporary Variable just for 'character_creation_function' Function's scripting)
// 'player' -> 'x'

msg ("What is your name?")
get input {
x.alias = result
// conceptually: player.alias = x.alias = result
}
</function>

// I type in for my name: HK

// A later (afterwards) scripting:
msg ("Your name is " + player.alias + ".")

// quest will output: Your name is HK.


you can also do more layers of Functions (Functions within Functions), changing the label over and over again, and also something I forgot to explain too:

function_X (position_1A, position_2A, position_3A, etc)

<function name="function_x" parameters="position_1B, position_2B, position_3B, etc">
</function>

the Parameters are matched up via their position:

position_1A -> position_1B
position_2A -> position_2B
position_3A -> position_3B

------

player.alias = "HK"
orc.alias = "zukor"

// msg (player.alias), outputs: HK
// msg (orc.alias), outputs: zukor

function_1 (player, orc)

// player -> self // conceptually: player = self
// orc -> enemy // conceptually: orc = enemy

<function name="function_1" parameters="self,enemy">
msg (self.alias) // outputs: HK
msg (enemy.alias) // outputs: zukor
function_2 (self,enemy)
</function>

// self -> abc // conceptually: player = self = abc
// enemy -> zyx // conceptually: orc = enemy = zyx

<function name="function_2" parameters="abc, zyx">
msg (abc.alias) // outputs: HK
msg (zyx.alias) // outputs: zukor
function_3 (abc, zyx)
</function>

// hopefully you get the transition'ing concept now:
// abc -> red // conceptually: player = self = abc = red
// zyx -> blue // conceptually: orc = enemy = zyx = blue

<function name="function_3" parameters="red,blue">
msg (red.alias) // outputs: HK
msg (blue.alias) // outputs: zukor
</function>


outside of their Functions:
// msg (red~blue~abc~zyx~self~enemy.alias) // outputs: ERROR, 'red~blue~abc~zyx~self~enemy' is an unknown object reference
// msg (player.alias) // outputs: HK
// msg (orc.alias) // outputs: zukor

-----

it's similiar in concept to the:

foreach (temporary_Variable, Object_name.List_name)
if (temporary_Variable.alias = "Silver") {
temporary_Variable.eat_ice_cream
} else if (temporary_Variable.alias = "HK") {
temporary_Variable.run_laps
}
}

HegemonKhan
Silver wrote:Although I'm just curious really. I'm learning stuff on a need-to-know basis. Although the more I learn, I realise I needed to know it much earlier than I thought. :lol:

That's why I'm pleased I haven't galloped ahead with my game. It would have been a nightmare I think.


THIS, is the reason:

HK's game making progress: 0 (ZERO) !!!!
(laughs)

the more I try to work on making a game, the more I realize, I got to learn to code a lot more stuff ... sighs.

Silver
Back to the OP - the problem I was having was it counted one, two, three, then missed a beat then one, two, three... for some reason. This solved it though:

compression.description = compression.description + 1
if (compression.description = 4) {
compression.description = 1
}


I have no idea why the first bit of code misses a beat though as it's essentially saying the same thing.

HegemonKhan
if you could post it, we can take a look as to why it doesn't work (usually, if it's not just a typo-like mistake, you got to mentally test out your function in your head, or on paper if you're math challenged and can't do it in your head, like me, lol: plug in the increasing values into your 'counting~increasing' function, and see where~why the error is occuring).

Silver
I have posted it! I can create a demo of it not working if you want.

It's weird. I thought you put the conditions first, but in this case it wants the conditions to come second.

jaynabonne
How do you know it counted one, two, three, missed a beat, etc? I only see it outputting when value is 1.

HegemonKhan
is this your code that is not working?

if (room.description = 4) {
room.description = 0
}
room description = room.description + 1
msg ("{if room.description=1:Wow, the code is right!}")


this should be working... I think...

unless it is a 'string' vs 'int' issue, or maybe you need to make it wait first (this is likely wrong ~ ie: not the case):

\\room script
if (room.description = 4) {
room.description = 0
}
room description = room.description + 1
on ready {
msg ("{if room.description=1:Wow, the code is right!}")
}

Silver
jaynabonne wrote:How do you know it counted one, two, three, missed a beat, etc? I only see it outputting when value is 1.


msg ("{if compression.description=1:string1}{if compression.description=2:string2}{if compression.description=3:string3}")


it returned a blank on 4 then returned string 1 again on 5.

Silver
HegemonKhan wrote:is this your code that is not working?

if (room.description = 4) {
room.description = 0
}
room description = room.description + 1
msg ("{if room.description=1:Wow, the code is right!}")


this should be working... I think...

unless it is a 'string' vs 'int' issue, or maybe you need to make it wait first (this is likely wrong ~ ie: not the case):

\\room script
if (room.description = 4) {
room.description = 0
}
room description = room.description + 1
on ready {
msg ("{if room.description=1:Wow, the code is right!}")
}


I've got it working, I just don't know why the first code example didn't work and the second one did. Well the first one did but skipped a ... er... number/value?

HegemonKhan
@Silver:

I was asking about the code of yours that doesn't~didn't work (I know you found a way to code it to work), in trying to help you understand (find out) why it wasn't working.

-------------------

wrong ordering:

decompression.description = 0

<function>
decompression.description = decompression.description + 1
if (decompression.description = 4) {
decompression.description = 0
}
if (decompression.description = 0) {
msg ("0") // this will never get outputed
} else if (decompression.description = 1) {
msg ("1")
} else if (decompression.description = 2) {
msg ("2")
} else if (decompression.description = 3) {
msg ("3")
} else if (decompression.description = 4) {
msg ("4") // this will never get displayed
}
// loop
</function>


VS

correct ordering:

decompression.description = 0

<function><![CDATA[
if (decompression.description > 4) {
decompression.description = 0
}
if (decompression.description = 0) {
msg ("0")
} else if (decompression.description = 1) {
msg ("1")
} else if (decompression.description = 2) {
msg ("2")
} else if (decompression.description = 3) {
msg ("3")
} else if (decompression.description = 4) {
msg ("4")
}
decompression.description = decompression.description + 1
// loop
]]></function>

jaynabonne
Silver, think about what happens if room.description is 3 in your original code. It bypasses the "if" (not 4 yet), and then gets incremented to 4. But you have no output for 4. The value at print time goes 1, 2, 3, 4, 1, 2, 3...

With your second code, the value cycles 1,2,3,1,2,3...

Silver
Heh. Jay has it. Human error always. :lol: To me it says the same thing. But yeah, you're right.

Silver
It wasn't 4 so it carried on to become 4 instead of 0. Derr. Brilliant though.

Silver
I think I'm in love with code. :D Something to ponder.

Silver
And sorry. If I'd given the full example in my OP this would have been solved much quicker. The problem is what I, as a novice, think I'm getting wrong and only showing those cards rather than the full suit.

My earlier problem was a bigger headache though. When using the text processor you only have to miss out one curly brace and the whole lot spits out at you in code in the room description.

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

Support

Forums