Inventory message
m4u
21 Nov 2013, 15:53Hi guys, how can I code this for the inventory message?
Instead of saying:
"You have a thing one and a thing two"
Something saying:
"You have:
(tab here) a thing one
(tab here) a thing two"
Instead of saying:
"You have a thing one and a thing two"
Something saying:
"You have:
(tab here) a thing one
(tab here) a thing two"
george
21 Nov 2013, 16:59I don't know if there's a simple answer for this, so I'll wait a bit to answer this the complicated way in the hope someone else will step in. However I'll point you to the complicated answer and maybe you can figure it out yourself.
* In the GUI click on the filter to show library elements (lower left hand corner).
* Then do a search for 'inventory' (search box is in upper left hand corner).
* You'll see the inventory command, click on that.
* copy that into your project
* In the script for that you'll see a list created from FormatObjectList, and the template CarryingListHeader.
* Do a search for CarryingListHeader -- you'll want to change that eventually so copy it into your project.
* Do a search for FormatObjectList. This is the complicated part.
* copy it into your project
* click on Code View in the script tool bar (second icon from the left in the toolbar on the same line as 'Script:')
* Above the script you'll see the Parameters box. These are the arguments to the function as called in the inventory command, where you saw FormatObjectList(Template("CarryingListHeader"), game.pov, Template("And"), ".", true).
So, the parameters are:
preList is Template("CarryingListHeader")
parent is game.pov
preFinal is Template("And")
postList is "."
useinventoryverbs is true
These are the elements of the inventory text returned when you do the command 'inventory', and are used in the FormatObjectList you see there in code view.
If you read the FormatObjectList code you'll notice that it calls itself, around line 15 where it says result = result + FormatObjectList(....). This is a recursive call and it's how it builds the full inventory list.
So, in a nutshell the complicated way is to rewrite this function to display inventory how you want. You'll also need to change the inventory command so that the parameters to FormatOBjectList are what you want. For example, you probably don't want the Template("And") in your inventory text.
Sorry I don't have time right now to take a cut at this but maybe someone else can, you can, or there's a simpler way I don't know. Good luck!
* In the GUI click on the filter to show library elements (lower left hand corner).
* Then do a search for 'inventory' (search box is in upper left hand corner).
* You'll see the inventory command, click on that.
* copy that into your project
* In the script for that you'll see a list created from FormatObjectList, and the template CarryingListHeader.
* Do a search for CarryingListHeader -- you'll want to change that eventually so copy it into your project.
* Do a search for FormatObjectList. This is the complicated part.
* copy it into your project
* click on Code View in the script tool bar (second icon from the left in the toolbar on the same line as 'Script:')
* Above the script you'll see the Parameters box. These are the arguments to the function as called in the inventory command, where you saw FormatObjectList(Template("CarryingListHeader"), game.pov, Template("And"), ".", true).
So, the parameters are:
preList is Template("CarryingListHeader")
parent is game.pov
preFinal is Template("And")
postList is "."
useinventoryverbs is true
These are the elements of the inventory text returned when you do the command 'inventory', and are used in the FormatObjectList you see there in code view.
If you read the FormatObjectList code you'll notice that it calls itself, around line 15 where it says result = result + FormatObjectList(....). This is a recursive call and it's how it builds the full inventory list.
So, in a nutshell the complicated way is to rewrite this function to display inventory how you want. You'll also need to change the inventory command so that the parameters to FormatOBjectList are what you want. For example, you probably don't want the Template("And") in your inventory text.
Sorry I don't have time right now to take a cut at this but maybe someone else can, you can, or there's a simpler way I don't know. Good luck!


Pertex
21 Nov 2013, 21:43[quote="george"
* Do a search for FormatObjectList. This is the complicated part.
* copy it into your project
[/quote]
It's better not to change FormatObjectList because it is used in the "Youcansee" function, too.
So it is better to create a similar function, something like this:
This function should do what you want, just change the call of the function in the inventory command from FormatObjectList to FormatObjectList2
* Do a search for FormatObjectList. This is the complicated part.
* copy it into your project
[/quote]
It's better not to change FormatObjectList because it is used in the "Youcansee" function, too.
So it is better to create a similar function, something like this:
<function name="FormatObjectList2" type="string" parameters="preList, parent, preFinal, postList, useinventoryverbs">
<![CDATA[
result = ""
count = 0
list = RemoveSceneryObjects(GetDirectChildren(parent))
if (CheckDarkness()) {
list = RemoveDarkObjects(list)
}
listLength = ListCount(list)
foreach (item, list) {
if (LengthOf(result) = 0) result = preList + "<br/>"
verbs = GetDisplayVerbs(item)
result = result + " " + GetDisplayNameLink(item, "object")
count = count + 1
if (count = listLength - 1) {
result = result + "<br/>"
}
else if (count < listLength) {
result = result + "<br/>"
}
}
return (result)
]]>
</function>
This function should do what you want, just change the call of the function in the inventory command from FormatObjectList to FormatObjectList2
Liam315
22 Nov 2013, 00:28This is the code I used to display my inventory as a list:
You might notice the part that says
There was an issue where items without a prefix weren't capitalising which this fixes, but it will cause you problems if you have some objects that don't have an alias.
On the subject of inserting tabs like you would on a word processor, the concept doesn't exist within html. What you can do is use the following:  
It stands for non-breaking space and it forces the whitespace to be preserved rather than collapsed into a single space. Put a few of those in front of the item in the above code and it should replicate the effect you're after.
if (ListCount(RemoveSceneryObjects(ScopeInventory())) = 0) {
msg ("You are not carrying anything.")
}
else {
msg ("You are carrying:<br/>")
foreach (item, GetDirectChildren(game.pov)) {
if (not item.scenery) {
if ((not item.usedefaultprefix) and (item.prefix = null)) {
msg (CapFirst(item.alias))
}
else {
invitem = GetDisplayNameLink(item,"object")
if (CanSeeThrough(item)) {
invitem = invitem + FormatObjectList(" (" + item.contentsprefix, item, Template("And"), ")", False)
}
msg (CapFirst(invitem))
}
}
}
}
You might notice the part that says
if (not item.scenery) {
if ((not item.usedefaultprefix) and (item.prefix = null)) {
msg (CapFirst(item.alias))
}
There was an issue where items without a prefix weren't capitalising which this fixes, but it will cause you problems if you have some objects that don't have an alias.
On the subject of inserting tabs like you would on a word processor, the concept doesn't exist within html. What you can do is use the following:  
It stands for non-breaking space and it forces the whitespace to be preserved rather than collapsed into a single space. Put a few of those in front of the item in the above code and it should replicate the effect you're after.
m4u
22 Nov 2013, 20:44Thank you guys! it's working. How can i achieve the same with the children list? Meaning when you type inventory something that says:
a thing containing:
(tab) a thing one
(tab) a thing two
a thing containing:
(tab) a thing one
(tab) a thing two
m4u
25 Nov 2013, 17:12Anyone?
george
27 Nov 2013, 06:12I modified Pertex's code a bit. It plays like this,
The new FormatObjectList2 is
I added the level parameter to keep track of the inventory nesting level. The this_level local variable is necessary to keep track of the proper level as you go down the main inventory list, showing children of objects in inventory. For convenience I added a Repeat function which is this,
Note you must modify the inventory command so it calls FormatObjectList2 like,
FormatObjectList2(Template("CarryingListHeader"), game.pov, Template("And"), ".", true, 1)
where '1' is the level parameter.
> i
You are carrying
a potion containing
a genie
a necklace containing
a pearl
a pendant
The new FormatObjectList2 is
<function name="FormatObjectList2" parameters="preList, parent, preFinal, postList, useinventoryverbs, level" type="string"><![CDATA[
result = ""
count = 0
list = RemoveSceneryObjects(GetDirectChildren(parent))
if (CheckDarkness()) {
list = RemoveDarkObjects(list)
}
listLength = ListCount(list)
this_level = level
foreach (item, list) {
level = this_level
if (LengthOf(result) = 0) {
result = preList + "<br/>"
}
verbs = GetDisplayVerbs(item)
result = result + Join(Repeat(level * 5, " "), "") + GetDisplayNameLink(item, "object")
if (CanSeeThrough(item)) {
level = level + 1
result = result + FormatObjectList2(" " + item.contentsprefix, item, preFinal, "", useinventoryverbs, level)
}
count = count + 1
if (count < listLength) {
result = result + "<br/>"
}
}
return (result)
]]></function>
I added the level parameter to keep track of the inventory nesting level. The this_level local variable is necessary to keep track of the proper level as you go down the main inventory list, showing children of objects in inventory. For convenience I added a Repeat function which is this,
<function name="Repeat" parameters="n, s" type="stringlist"><![CDATA[
ss = NewStringList()
count = 0
while (count < n) {
count = count + 1
list add (ss, s)
}
return (ss)
]]></function>
Note you must modify the inventory command so it calls FormatObjectList2 like,
FormatObjectList2(Template("CarryingListHeader"), game.pov, Template("And"), ".", true, 1)
where '1' is the level parameter.