lining text up in a message (or elsewhere)
Kit_sune
23 Oct 2012, 03:40One of the Information Systems I work with has a report writing language that allows you to specify columns to print your data from.
For instance if you put:
"line 1 column 2"
It would start printing from line one, and the first data field would print on column two of that line.
Well I want to print a message, but I want things to line up properly so it looks more organized. It's supposed to look like a card, in the long run.
I want it to look like this:
See how "CP" and "CP Refresh" start on the same column?
This is the code I have. (let it be known I love yoshi, heh...) It's under the "look" statement.
As you can see by the spaces inside the quotes, I tried to line them up myself but it condensed all the space " " into one space " " when it printed.
For instance if you put:
"line 1 column 2"
It would start printing from line one, and the first data field would print on column two of that line.
Well I want to print a message, but I want things to line up properly so it looks more organized. It's supposed to look like a card, in the long run.
I want it to look like this:
Green Yoshi
Green Yoshis have very little magic or color abilities, instead they rely on old fashioned physical strength, and endurance to get the job done.
HP: 20
FP: 0 CP: 0
FP Refresh: 3 CP Refresh: 2
See how "CP" and "CP Refresh" start on the same column?
This is the code I have. (let it be known I love yoshi, heh...) It's under the "look" statement.
<object name="Green Yoshi1">
<inherit name="switchable" />
<alias>Green Yoshi</alias>
<desc>Green Yoshis have very little magic or color abilities, instead they rely on old fashioned physical strength, and endurance to get the job done.</desc>
<hp type="int">20</hp>
<atk type="int">4</atk>
<spd type="int">3</spd>
<endure type="int">6</endure>
<fp type="int">0</fp>
<fprefresh type="int">3</fprefresh>
<cp type="int">0</cp>
<cprefresh type="int">2</cprefresh>
<usedefaultprefix type="boolean">false</usedefaultprefix>
<displayverbs>look at; choose</displayverbs>
<inventoryverbs>Look at; Use; Discard</inventoryverbs>
<attr name="Green Yoshi" type="string"></attr>
<scenery type="boolean">false</scenery>
<choose type="script">
player.hp = this.hp
</choose>
<look type="script">
msg (this.alias)
msg (this.desc)
msg ("HP: " + this.hp)
msg ("FP: " + this.fp + " CP: " + this.fp)
msg ("FP Refresh: " + this.fprefresh + " CP Refresh: " + this.cprefresh)
</look>
</object>
As you can see by the spaces inside the quotes, I tried to line them up myself but it condensed all the space " " into one space " " when it printed.


guzmere
23 Oct 2012, 05:59Hi Kit_sune hope you are well on this dark morning. Pertex came up with this coding for placing spaces in the text. Have a look at the upload it's basic but it gives you the idea of it. There is the function of whitespaces on the tree at the side and the room holds the second part. Have fun hope this is what you meant. Terry





The Pixie
23 Oct 2012, 07:47The reason white space is collapsed is because output in Quest is HTML, and this is the standard for HTML. It makes sense on a web page, but perhaps less so here. Quest uses HTML to make output for online games easier.
In HTML you could do this using <pre> tags or entities, but this is a cut down version of HTML, and neither are available here.
As guzmere has said, Pertex has a function that will give a specified number of white spaces. The way it works is that Quest interpretes a row of space inside an HTML element as a row of spaces instead of collapsing it, so this will work:
The <b> tag turns on bold, and stops the spaces getting collapsed. However, if the whole line is in bold, white space is still collapsed. This does not work:
This is not stardard HTML, and I have no idea why it should work, but it does.
Anyway, I was actually thinking about formatting a table last night, and this has prompted me to create these functions (the Whitespaces function is Pertex's).
With FormatText, send it two strings, the first being the number of characters allocated to each column, the second being the values for each column, separated by semi-columns in both cases (alternatively, use FormatTextLists and send string lists with the data). Your look script now looks like this:
It looks best if you set the font to one like Courier New where all the characters are the same width. You could do that in the script so only the table is in that font.
In HTML you could do this using <pre> tags or entities, but this is a cut down version of HTML, and neither are available here.
As guzmere has said, Pertex has a function that will give a specified number of white spaces. The way it works is that Quest interpretes a row of space inside an HTML element as a row of spaces instead of collapsing it, so this will work:
msg ("FP: " + this.fp + "<b> </b>CP: " + this.fp)
The <b> tag turns on bold, and stops the spaces getting collapsed. However, if the whole line is in bold, white space is still collapsed. This does not work:
msg ("<b>FP: " + this.fp + " CP: " + this.fp + "</b>")
This is not stardard HTML, and I have no idea why it should work, but it does.
Anyway, I was actually thinking about formatting a table last night, and this has prompted me to create these functions (the Whitespaces function is Pertex's).
<function name="FormatText" parameters="columns, strings">
FormatTextLists (Split (columns, ";"), Split (strings, ";"))
</function>
<function name="FormatTextLists" parameters="columns, strings"><![CDATA[
str = ""
for (i, 0, ListCount (columns) - 1) {
s = StringListItem (columns, i)
if (not IsNumeric (s)) {
error ("ERROR: " + s + " is not a number in FormatText")
}
cols = ToInt (s)
if (ListCount (strings) > i) {
s = StringListItem (strings, i)
str = str + s + Whitespaces (cols - LengthOf (s))
}
}
msg (str)
]]></function>
<function name="Whitespaces" parameters="number" type="string"><![CDATA[
text = ""
for (x, 1, number) {
text = text+ " "
}
return ("<b>"+text+"</b>")
]]></function>
With FormatText, send it two strings, the first being the number of characters allocated to each column, the second being the values for each column, separated by semi-columns in both cases (alternatively, use FormatTextLists and send string lists with the data). Your look script now looks like this:
<look type="script">
msg (this.alias)
msg (this.desc)
msg ("HP: " + this.hp)
cols = "12;10;12;10"
FormatText (cols, "FP:;" + this.fp + ";CP:;" + this.cp)
FormatText (cols, "FP Refresh:;" + this.fprefresh + ";CP Refresh:;" + this.cprefresh)
</look>
It looks best if you set the font to one like Courier New where all the characters are the same width. You could do that in the script so only the table is in that font.
Kit_sune
23 Oct 2012, 19:32Very cool Guzmere, Pixie, thank you!
I've tested them, and they work perfectly. It seems like everything I want to do requires building a function...
I'm going to have to work harder to learn how to build my own functions properly. It might have to wait though, because all this code stuff has been giving me a headache.
I was working on a big project, but I decided to put it on the backburner and create a test game to help me learn how this stuff works better - which is why I switched from demons, to yoshis.
It's similar to a card simulator, where you have a couple decks of cards and you draw them to your hands. But each card has stats, and affects. I found a function that is supposed to be available "ScopeInventory()" where it builds a list of all the items in the player's inventory. I thought this would be a good way to show the player their hand.
But like I said earlier, I think my headache is making it harder for me to concentrate on this stuff so I'll have to come back to it.
I've tested them, and they work perfectly. It seems like everything I want to do requires building a function...

I'm going to have to work harder to learn how to build my own functions properly. It might have to wait though, because all this code stuff has been giving me a headache.
I was working on a big project, but I decided to put it on the backburner and create a test game to help me learn how this stuff works better - which is why I switched from demons, to yoshis.
It's similar to a card simulator, where you have a couple decks of cards and you draw them to your hands. But each card has stats, and affects. I found a function that is supposed to be available "ScopeInventory()" where it builds a list of all the items in the player's inventory. I thought this would be a good way to show the player their hand.
But like I said earlier, I think my headache is making it harder for me to concentrate on this stuff so I'll have to come back to it.

guzmere
24 Oct 2012, 06:24Hi, functions are a necessary part of quest (I think) but once written can be called on throughout the game and as many times as you like. (Simple to the complex) is a famous quote from someone and I tend to agree (with that someone) Why make headaches for yourself when you can do the same the same thing without all the pain. If you learn to understand the breakdown of the Scope Inventory then please post it with the card game it would be interesting to see under the hood so to speak. Keep taking the headache pills you'll sleep better LOL.
Terry




Kit_sune
25 Oct 2012, 17:43Ok. I’ve hit that point where I just want to throw my laptop on the floor because I’m still trying to learn the basics of this stuff.
Before you ask, yes I’ve been through the tutorials, and help screens.
I’ve tried writing this countless ways and I don’t want to try anymore. I’m guessing the problem is the ‘s’ in “ msg ("Number: " s)” but nothing I’ve tried there seemed to work. What is my mistake?
Error running script: Unable to cast object of type 'System.Int32' to type 'System.String'.
<command name="test1">
<pattern>test</pattern>
<script>
testList = NewStringList()
list add (testList, 1)
list add (testList, 2)
list add (testList, 3)
foreach (s, testList) {
msg ("Number: " s)
}
</script>
</command>
Also, if someone could breakdown all the aspects of a function for me, that would be super awesome. What information do you need to create a complex function, because on the wiki,
doesn't really help me very much.
blahhhh
Before you ask, yes I’ve been through the tutorials, and help screens.
I’ve tried writing this countless ways and I don’t want to try anymore. I’m guessing the problem is the ‘s’ in “ msg ("Number: " s)” but nothing I’ve tried there seemed to work. What is my mistake?
Error running script: Unable to cast object of type 'System.Int32' to type 'System.String'.
<command name="test1">
<pattern>test</pattern>
<script>
testList = NewStringList()
list add (testList, 1)
list add (testList, 2)
list add (testList, 3)
foreach (s, testList) {
msg ("Number: " s)
}
</script>
</command>
Also, if someone could breakdown all the aspects of a function for me, that would be super awesome. What information do you need to create a complex function, because on the wiki,
<function name=" name " optional type=" type " optional parameters=" parameters "> script </function>
doesn't really help me very much.
blahhhh
The Pixie
25 Oct 2012, 19:45msg ("Number: " s)
should be
msg ("Number: " + s)
should be
msg ("Number: " + s)

jaynabonne
25 Oct 2012, 20:23Kit_sune, I'm not sure what you mean by "complex", but we can break down the various aspects of the function. (Complexity is really a measure of what you do in the body of your function.)
The attributes of a function:
- name: This is the name of the function. Every function must have name, and that is the name you use to invoke the function in some other script.
- parameters: These are the values (if any) passed into the function. You give them names, and when the function is called, those parameters must be set by giving values in the function call (e.g. MyFunction(a, b) ). The values are mapped to the parameters in the order they are given. If your function does not take input parameters, then you can omit this or leave it as an empty string.
- type: This is the return type of the function (the value passed out), if the function returns a value. Some functions do, and some don't. If you use a "return" statement in your function to send a value back to the caller, then you need to specify the return type, so that Quest knows what type the function is expected to return. If your function does not return a value, then you can omit this or leave it an empty string.
Here is a trivial example. It's a function to concatenate two strings and return the result. Clearly, you don't need this function (since you can just use the "+" yourself), but I hope it illustrates how functions are set up.
This basically says, "We have a function called 'ConcatStrings', it takes two input parameters, which we will call 's1' and 's2' inside the function, and the function returns a string value."
The function would be invoked as:
The resulting "s" would be "Mama Mia"
I hope that helps!
<function name=" name " optional type=" type " optional parameters=" parameters "> script </function>
The attributes of a function:
- name: This is the name of the function. Every function must have name, and that is the name you use to invoke the function in some other script.
- parameters: These are the values (if any) passed into the function. You give them names, and when the function is called, those parameters must be set by giving values in the function call (e.g. MyFunction(a, b) ). The values are mapped to the parameters in the order they are given. If your function does not take input parameters, then you can omit this or leave it as an empty string.
- type: This is the return type of the function (the value passed out), if the function returns a value. Some functions do, and some don't. If you use a "return" statement in your function to send a value back to the caller, then you need to specify the return type, so that Quest knows what type the function is expected to return. If your function does not return a value, then you can omit this or leave it an empty string.
Here is a trivial example. It's a function to concatenate two strings and return the result. Clearly, you don't need this function (since you can just use the "+" yourself), but I hope it illustrates how functions are set up.
<function name="ConcatStrings" parameters="s1, s2" type="string">
return (s1 + s2)
</function>
This basically says, "We have a function called 'ConcatStrings', it takes two input parameters, which we will call 's1' and 's2' inside the function, and the function returns a string value."
The function would be invoked as:
s = ConcatStrings("Mama ", "Mia")
The resulting "s" would be "Mama Mia"
I hope that helps!
The Pixie
26 Oct 2012, 07:18jaynabonne, I have updated the Wiki page using your post; hope you do not mind (and credited you on the discussion page).
Alex, on the Wiki, on the navigation panel on the left, should there be a link to "Elements" under Quest Documentation, to go with attributes, commands, etc.? It is not easy finding elements without it.
Alex, on the Wiki, on the navigation panel on the left, should there be a link to "Elements" under Quest Documentation, to go with attributes, commands, etc.? It is not easy finding elements without it.
Alex
26 Oct 2012, 08:24Makes sense. The sidebar links are in a special wiki page... somewhere (I always have to look it up - maybe you can edit it or maybe it needs an admin to do it)

jaynabonne
26 Oct 2012, 09:00Thanks very much, Pixie! 
