Does "on ready" work?

The Pixie
16 Jul 2013, 20:57
For the backgrounmd, see this thread:
viewtopic.php?f=18&t=3789

What I am trying to do is set up a spell book; player types "CAST UNLOCK", and a spell from the spell book is cast. The problem is that spells in the spellbook are not in a convential scope, so I am trying to match text instead of an object.

  <command name="Cast">
<pattern>cast #text#</pattern>
<script>
// stuff here
</script>
</command>


Jay pointed me to ResolveNameInternal, and that got me going, but when you get to disambiguation, it all goes weird. The problem is that the command completes without waiting for the menu to get a response.

But wait, that is just what "on ready" is for, right?

So here it is:

  <command name="Cast">
<pattern>cast #text#</pattern>
<script><![CDATA[
value = LCase (text)
scope = GetDirectChildren (spellbook)
fullmatches = NewObjectList()
partialmatches = NewObjectList()
value = Trim(value)
foreach (obj, scope) {
name = LCase(GetDisplayAlias(obj))
CompareNames (name, value, obj, fullmatches, partialmatches)
if (obj.alt <> null) {
foreach (altname, obj.alt) {
CompareNames (LCase(altname), value, obj, fullmatches, partialmatches)
}
}
}
if (game.lastobjects <> null) {
foreach (obj, game.lastobjects) {
CompareNames (LCase(obj.article), value, obj, fullmatches, partialmatches)
CompareNames (LCase(obj.gender), value, obj, fullmatches, partialmatches)
}
}
if (ListCount(fullmatches) = 1) {
spellbook.spellpending = ListItem(fullmatches, 0)
}
else if (ListCount(fullmatches) = 0 and ListCount(partialmatches) = 1) {
spellbook.spellpending = ListItem(partialmatches, 0)
}
else if (ListCount(fullmatches) + ListCount(partialmatches) = 0) {
spellbook.spellpending = null
}
else {
menu = NewStringDictionary()
GenerateMenuChoices (menu, fullmatches)
GenerateMenuChoices (menu, partialmatches)
ShowMenu (DynamicTemplate("DisambiguateMenu", value), menu, true) {
if (result <> null) {
spellbook.spellpending = GetObject(result)
}
else {
spellbook.spellpending = null
}
}
}
on ready {
if (spellbook.spellpending = null) {
msg ("No such spell in your book")
}
else if (not HasScript (spellbook.spellpending, "castspell")) {
msg ("That's not a spell; it should not even be in your book")
}
else {
do (spellbook.spellpending, "castspell")
}
}
]]></script>
</command>


But it fails. The "on ready" bit does not wait for the menu to complete. Why is that?

Code here:


You will also need Jay's library file from the above thread.

jaynabonne
16 Jul 2013, 21:55
I believe the new style menus don't use a mechanism that "on ready" listens for. They're done directly in ASL code as opposed to being done in state-driven JS code. (I could be wrong.)

The Pixie
17 Jul 2013, 07:44
Thanks for pointing me in the right direction, but actually you have that the wrong way around. The new style "show menu" does work, it is the old "ShowMenu" that does it wrong.

I have filed a bug about ResolveNameInternal still using ShowMenu, now show menu
https://quest.codeplex.com/workitem/1311

Alex
17 Jul 2013, 09:08
ShowMenu is a new core library function in Quest 5.4.

Quest 5.0 had an old ShowMenu function, which was superseded by the "show menu" script command in Quest 5.1. That itself is superseded by the new ShowMenu in 5.4 which displays an in-line hyperlink menu instead of the older popup.

jaynabonne
17 Jul 2013, 10:06
I wanted to post this since I just discovered something relevant trying Pertex's RPG/Combat lib, which uses the old (deprecated) ShowMenu. I think it makes more sense to me now, and maybe it will help someone.

1) The original ShowMenu was an *expression* function, built into the FLEE expression system, which put up a menu, blocked, and then returned the result as its return value. If you try to do something like this now:

result = ShowMenu(...)

then you get (as of 5.4.1):

The 'ShowMenu' function is not supported for games written for Quest 5.4 or later. Use the 'show menu' script command instead.

which is sort of kinda maybe not correct (depending on what you want - there is the new ShowMenu function).

2) This was deprecated and replaced with "show menu", which passed the result value to a script. This function uses the old style popup approach.

3) There is a new ShowMenu core (not expression) function which now does inline menus and also pases the result to a passed script.

I hope that is correct and makes sense. (I have faced some confusion in the docs about what is deprecated/obsolete and what is not. I think the two different versions of ShowMenu is part of that problem.)

The Pixie
17 Jul 2013, 15:03
Alex wrote:ShowMenu is a new core library function in Quest 5.4.

Quest 5.0 had an old ShowMenu function, which was superseded by the "show menu" script command in Quest 5.1. That itself is superseded by the new ShowMenu in 5.4 which displays an in-line hyperlink menu instead of the older popup.

Okay, that makes sense...

The Wiki has nothing about a new ShowMenu, only saying it is deprecated.

So what is the work-around with the new ShowMenu for the on ready thing?