Conditionally Hide Compass?

Vikkal
30 May 2013, 05:33
I have a question about the side panes. Is there a way to conditionally hide the compass pane? That is, in the game I'm developing I want players to have the option of whether or not the compass shows up, tied to an in game item called "Compass". If they have the Compass object in their inventory I want the compass pane to show up, but if they do not have the Compass object I don't want the compass pane to show up.

I have looked through the forums, but so far all I've been able to find is based on permanently hiding sections of the side panes. I'm new to Quest so this might be silly-obvious one way or another, but some help would be appreciated.

Edit: I'm using the latest version of Quest, 5.4 I think.

Sora574
30 May 2013, 06:01
You could just add to the take/drop scripts.
So go to the 'compass' object, then go to the 'Inventory' tab.
Click the 'Add new script' button under 'After taking object:'
Select 'Run Javascript' from the 'Output' section.
Paste this into the box:
eval ("$('#compassLabel').show(); $('#compassAccordion').show();")

Now, do the same thing for 'After dropping the object:', except put this into the JavaScript box:
eval ("$('#compassLabel').hide(); $('#compassAccordion').hide();")


Test the game and you'll see that the compass will disappear when you drop the object, and reappear when you pick it up.

Vikkal
30 May 2013, 06:16
Thanks! That worked perfectly (and will give me a base for other similar objects). Although, is there a way to get it to work with the side panels disabled or hidden from the start? The idea is that the player won't be able to see the compass pane until after they pick up the compass object from the beginning. When testing it with the side panels disabled nothing happens. Javascript is not my strong suit :lol: .

Edit: I'm such a derp sometimes. I can just apply the "hide" script to the Game>Script. :oops: Thank you!

guzmere
30 May 2013, 07:30
Hi Vikkal hope you are well. Question what did you mean by ( applying the "hide" script to the Game>Script.) Because this is something that I may be interested in at a later time. I think the idea is quirky and very clever. Thanks Terry :D Happy Adventuring :D P. S. don't mean to pinch your ideas, but well worth thinking about.

Vikkal
30 May 2013, 07:47
Well, I may be doing something seriously wrong so don't hold me to it (I'm still learning Quest behavior), but I just went into Game>Script and added a new "Run Javascript" in the Start Script box, with the second code Sora gave (In addition to adding it to the object's drop behavior).

So far it seems to work. The player can't see the compass pane until after they pick up the compass object, and when they drop the compass object it just goes back to hiding the compass pane like normal. I might plan to adapt it for the Inventory as well, so that the players can't see the Inventory pane until after they pick up a "Bag" object in game.

guzmere
30 May 2013, 10:14
Yeah thanks for that got it working too. Terry :D Happy Adventuring :D

Sora574
30 May 2013, 12:23
Vikkal wrote:I might plan to adapt it for the Inventory as well, so that the players can't see the Inventory pane until after they pick up a "Bag" object in game.
If you do that, you can just use the same scripts except replace 'compass' with 'inventory'... Pretty simple, right?

Also, if you're interested, you can change where it says 'Inventory' in-game to whatever you want. You have to switch to code view, though (the little notepad/paper thing above any script) and, if you wanted it to say 'Bag', type
request (SetInterfaceString, "InventoryLabel=Bag")

Basically, anything you put after the '=' is what shows up.

Vikkal
31 May 2013, 06:01
Ooo, thank you Sora! I had figured out how to hide the Objects and Rooms pane too, but had been confused about whether or not the actual names could be changed. I'll definitely have to play around with it.

Glad it worked for you too, Guzmere!

Edit: Here's an unrelated question, if anyone can help. In an expression using variables, is there a way to get the text to conditionally use a/an. For example:

msg ("You are a " + game.pov.race + " " + game.pov.class+ " named " + game.pov.alias + ".")


In this sentence "a" works well for most races, however in the case of "Angel" race it reads "a angel" instead of "an angel". But, I don't want to have to name each race/class "an angel" or "a demon" or create a complicated system just for two words (unless it's required).

(I don't want to create a new thread for such a tiny issue :) )

Pertex
31 May 2013, 08:14
If you are creating an english game you can use the function GetDefaultPrefix (object)

Vikkal
31 May 2013, 08:46
How would I go about adding the function GetDefaultPrefix (object)? Would I actually Call Function, plug it into the expression, or add it to the game.pov.race variable? I'm gaining a good grasp of what to do for most things, but new things trip me up :lol: .

Liam315
31 May 2013, 09:20
You would just use it as an expression in place of the "a" as you print your message.

msg ("You are " + GetDefaultPrefix(game.pov.race) + " " + game.pov.race + " " + game.pov.class+ " named " + game.pov.alias + ".")

Vikkal
31 May 2013, 09:33
That produces the error:

Error running script: Error evaluating expression 'HasString(obj, "alias")': HasString function expected object parameter but was passed 'Angel'
You are an Angel Priest named Vikkal.

So the message prints correctly but with the error above it.

Liam315
31 May 2013, 09:44
Sorry, that's because game.pov.race is an attribute, not an object. You might actually need to define your own prefix script. If Angel is the only race beginning with a vowel then just use something like

if (game.pov.race = "Angel") {
raceprefix = "an"
}
else {
raceprefix = "a"
}
msg ("You are " + raceprefix + " " + game.pov.race + " " + game.pov.class+ " named " + game.pov.alias + ".")

Vikkal
31 May 2013, 09:57
Thank you! That worked perfectly!

jaynabonne
31 May 2013, 17:54
Here's one that works with any race:

raceprefix = if (LCase(Left(game.pov.race, 1)) in ("a", "e", "i", "o", "u"), "an", "a")

Of course, you could make it a function...

Vikkal
31 May 2013, 18:20
Thank you, Jaynabonne! That one will be infinitely useful for the classes as well as the races, especially since I will eventually be adding more races/classes with more varied names.

Sora574
01 Jun 2013, 00:16
Hmm... I think the GetDefaultPrefix function should parse both strings and objects. Wouldn't that make sense?...
It wouldn't be too difficult, you would just need something like this:
<function name="GetDefaultPrefix" parameters="param">
if (IsString(param)) {
if (Instr("aeiou", LCase(Left(param, 1))) > 0) {
return ("an")
}
else {
return ("a")
}
}
else {
if (Instr("aeiou", LCase(Left(GetDisplayAlias(param), 1))) > 0) {
return ("an")
}
else {
return ("a")
}
}
</function>

jaynabonne
01 Jun 2013, 09:12
I agree. (General-purpose functions, please!) You could even reduce redundancy by having it invoke itself in the object case:
<function name="GetDefaultPrefix" parameters="param">
if (IsString(param)) {
if (Instr("aeiou", LCase(Left(param, 1))) > 0) {
return ("an")
}
else {
return ("a")
}
}
else {
return (GetDefaultPrefix(GetDisplayAlias(param)))
}
</function>

Vikkal
06 Jun 2013, 17:30
As another tangent, Whenever I enable the maps in my game I get this error:

Error running script: Error compiling expression 'room.grid_x - room.grid_parent_offset_x': ArithmeticElement: Operation 'Subtract' is not defined for types 'Object' and 'Double'

I have not changed or messed with the code or settings since the last time I enabled the maps and it worked fine last night. I only get the error when Playing through one specific game, the rest work fine. Did I maybe tweak something without realizing?

jaynabonne
06 Jun 2013, 19:00
DId you override the StartGame script at all? I have seen the error your experiencing if the grid code in that script is not run.

Vikkal
06 Jun 2013, 19:08
On this new game I haven't touched the startgame script, which is the weird part since the map works on my other games where I have changed it.

jaynabonne
06 Jun 2013, 19:13
Another thought: have you switched the player/pov or changed the parent/room in script? I don't know if the map code handles that gracefully (or at all :) ).

Vikkal
06 Jun 2013, 19:25
Oh, it could be that I have rooms in rooms to try keeping the GUI orderly. Instead of having everything scattered all over the place I like using rooms to categorize items and map regions. Could that break the map since the parent room isn't accessible? I also did move the player object into a new "Introduction" room which is independent of the rest; they get transported into the main start room after pressing a key, and that error only comes up after the key press.

jaynabonne
06 Jun 2013, 19:31
The problem is that the map code makes certain assumptions. One is that it assumes that the room the player is in during StartGame is the one he'll be in at the start - certain initialization happens there. So if you move the player, that initialization is not done, and things go south. It also breaks if you move the player later in the game.

What you could try is to put part of that code in where you do the jump. I'd try - before you assign the player to the target room - that you do something like:

        MainRoom.grid_x = 0
MainRoom.grid_y = 0
MainRoom.grid_z = 0
MainRoom.grid_render = true


That will set the variables that are normally set in StartGame.

Having nested rooms should not be a problem. All that matters is the room that's the player/pov's immediate parent. So organize away. :) (I do the same thing.)

Vikkal
06 Jun 2013, 22:14
I've tried several variations with that code and each time it produces a new error:

Error running script: Error compiling expression '(room.parent.grid_width - room.grid_width) /2.0': ArithmeticElement: Operation 'Subtract' is not defined for types 'Object' and 'Int32'
Error running script: Error compiling expression 'room.grid_render': RootExpressionElement: Cannot convert type 'Object' to expression result of 'Boolean'
Error running script: Error compiling expression '(room.parent.grid_width - room.grid_width) /2.0': ArithmeticElement: Operation 'Subtract' is not defined for types 'Object' and 'Int32'

Here is the setup I'm using. I'm probably doing something glaringly obviously wrong :oops: I've been working on my other game for 12 hours straight, so switching to this one kind of broke my brain :lol: .

</start>
<object name="Introduction">
<inherit name="editor_room" />
<usedefaultprefix type="boolean">false</usedefaultprefix>
<description type="script">
msg ("Blah Blah Blah")
MainRoom.grid_x = 0
MainRoom.grid_y = 0
MainRoom.grid_z = 0
MainRoom.grid_render = true
wait {
ClearScreen
MoveObject (player, MainRoom)
}
</description>
<object name="player">
<inherit name="editor_object" />
<inherit name="editor_player" />
<hideafter />
</object>
</object>
</game>

jaynabonne
06 Jun 2013, 22:52
Strange... If you take the room out of the game object it works. I guess it *does* matter if the parent room has a parent. :(

Vikkal
06 Jun 2013, 23:26
Thank you either way! I can probably compromise and just have players go into the main room via a one way exit from the Intro page. It will eliminate the need for MoveObject into a child room and hopefully correct the error.