Printing Blank Spaces [Solved]
Dcoder
10 Feb 2017, 19:44Pixie's original code for typing blank spaces before a text message (like an indent):
<function name="Whitespaces" parameters="number" type="string"><![CDATA[
game.command_successful = True
text = ""
for (x, 1, number) {
text = text+ " "
}
return (text)
]]></function>
I pasted the code into the "code view" and it shows up fine as a new function named "Whitespaces". Problem is, how do you make this function work with a printed message? I tried calling the Whitespaces function, printing the message as an expression, etc., to no avail. Help!
hegemonkhan
10 Feb 2017, 20:43Pixie's Function returns a given number of spaces/whitespaces (it's like a dynamic-sized 'tab' key), so you got to concatenate (literally means put togehter) this 'dynamic tab' with the message/text you want.
concepts:
Concatenation (only with strings can you do so):
"4" + "4" = "44"
"44" + "44" = "4444"
"44" + "44" + "44" = "444444"
"mama" + "mia" = "mamamia"
"mama" + " " + "mia" = "mama mia"
"mama " + "mia" = "mama mia"
"mama" + " mia" = "mama mia"
"mama" + "4" = "mama4"
"mama" + "4" + "mia" = "mama4mia"
"mama" + 4 = ERROR!
VS
Addition:
4 + 4 = 8
44 + 44 = 88
44 + 44 + 44 = 132
"mama" + 4 = ERROR!!
"4" + 4 = ERROR!
(though, I think quest, knows to / will automatically, parse a number into a string, so you won't have an error of doing: string + number/int-integer/double)
this is an example of how you'd do the catenation:
// in-code:
dynamic_tab_string_variable = Whitespaces (8) // I forgot whether a normal tab is 4 or 8 spaces, lol.
msg (dynamic_tab_string_variable + "blah blah blah")
// in GUI/Editor:
set variable dynamic_tab_string_variable = [EXPRESSION] Whitespaces (8)
print [EXPRESSION] dynamic_tab_string_variable + "blah blah blah"
-----
// output (the underscores represent spaces/whitespaces):
________blah blah blah
// --------------------------------------------
// P.S.
// you can put this 'dynamic tab' anywhere, it doesn't have to be at the beginning of your message:
// in-code:
dynamic_tab_string_variable = Whitespaces (8) // I forgot whether a normal tab is 4 or 8 spaces, lol.
msg ("blah blah blah" + dynamic_tab_string_variable + "blah blah blah")
// in GUI/Editor:
set variable dynamic_tab_string_variable = [EXPRESSION] Whitespaces (8)
print [EXPRESSION] "blah blah blah" + dynamic_tab_string_variable + "blah blah blah"
-------
output (underscores represent spaces/whitespaces):
blah blah blah________blah blah blah
// ----------
also, you can have your message be held by a VARIABLE of it's own too:
(in-code example only, too lazy to show via using GUI/Editor, you already/should know how to do it)
my_msg = "blah blah blah"
dynamic_tab_string_variable = Whitespaces (8)
msg (my_msg + dynamic_tab_string_variable + my_msg + dynamic_tab_string_variable + my_msg)
output: blah blah blah_______ blah blah blah_______blah blah blah
Pertex
10 Feb 2017, 20:53You can call it this way:
msg ("Hello" + Whitespaces(4) + "World")
By the way you can remove this line:
game.command_successful = True
Dcoder
10 Feb 2017, 21:42All right, it worked. What I learned is that the last line:
return (text)
returns the function as a string value that I can just plug into a printed expression. Simple but very useful.
Now on to vastly more complicated issues! Thank you both for your quick responses!
hegemonkhan
11 Feb 2017, 09:24http://docs.textadventures.co.uk/quest/elements/function.html
the 'type' signature/header option specifies that this function (now) must have a return value and that value's type must be what it is to be specified as by you: return's attribute/data type, for examples:
if you don't add/type in the 'type' signature/header option and its value (via in-code) and/or don't specify its type (via GUI/Editor), then your function has no return value, which is completely fine. Function's don't have to return a value.
-----------
<function name="return_string_concatenation_function" parameters="string_1_parameter, string_2_parameter" type="string">
return (string_1_parameter + string_2_parameter)
</function>
// example scripting:
string_variable = return_string_concatenation_function ("water", "world")
msg (string_variable)
// output: waterworld
-------------
<function name="return_integer_addition_function" parameters="integer_1_parameter, integer_2_parameter" type="int">
return (integer_1_parameter + integer_2_parameter)
</function>
// example scripting:
integer_variable = return_integer_addition_function (23, 45)
msg (integer_variable)
// output: 68
----------
you get the idea.... of how the 'type' header/signiature option works now... I hope...
Sebastian2203
11 Feb 2017, 17:04Hello, I am fairly new to Quest and I quickly skimmed to reply so sorry if I my advice will be wrong/useless to you but,
as far as I understand you are trying to type blank spaces because pressing space five times will only result in ONE blank space.
Well, if you quickly press ALT+0+1+6+1+0 it will create a special blank character that Quest won´t "ignore".
That´s all I know.