Text Processor reference an object

Avantar
19 Nov 2014, 20:48
If I have a room called 'room' and inside that room is a ball - I would want the description say that there is a ball in the room using the text processor. I am just struggling to reference the room.

{if ball.parent=room:You can see a ball} - Does not work. How does one reference the parent object using the text processor.

Any help will be much appreciated..

Avantar
19 Nov 2014, 20:53
Can this even be done in the text processor I wonder - Do not see an example in the wiki.

Silver
19 Nov 2014, 20:55
I don't really understand the text processor so feel free to ignore me but isn't checking the parent irrelevant if the player object is in the room?

Avantar
19 Nov 2014, 20:58
If the player takes the ball, the description should not display anymore. Would be funny still seeing the ball in the room when it is in your inventory.

Silver
19 Nov 2014, 21:07
Is this in TA or GB mode?

The Pixie
19 Nov 2014, 21:44
It is not possible. Querst is trying to match ball.parent, which is an object called room, with a string, "room", and finds they are different. What you need to do is compare ball.parent.name = room... but the text processor will not allow that (strinckly one dot at most).

If you are doing a TA (may need to be off-line)...

Go to Filter (bottom left) and click Show Library Elements. In the grey functions, look for ProcessTextCommand_If, and select it. Click Copy (top right), then where is says Script in the middle area, click the seventh icon, Code View. Replace everything there with this:

command = Mid(section, 4)
colon = Instr(command, ":")
if (colon = 0) {
return ("{if " + command + "}")
}
else {
text = Mid(command, colon + 1)
condition = Left(command, colon - 1)
operator = Instr(condition, "<=")
if (operator <> 0) {
operatorlength = 2
}
if (operator = 0) {
operator = Instr(condition, ">=")
if (operator <> 0) {
operatorlength = 2
}
}
if (operator = 0) {
operator = Instr(condition, "<>")
if (operator <> 0) {
operatorlength = 2
}
}
if (operator = 0) {
operator = Instr(condition, "<")
if (operator <> 0) {
operatorlength = 1
}
}
if (operator = 0) {
operator = Instr(condition, ">")
if (operator <> 0) {
operatorlength = 1
}
}
if (operator = 0) {
operator = Instr(condition, "=")
if (operator <> 0) {
operatorlength = 1
}
}
if (operator = 0) {
checkfor = true
if (StartsWith(condition, "not ")) {
checkfor = false
condition = Mid(condition, 5)
}
dot = Instr(condition, ".")
if (dot = 0) {
result = GetBoolean(game, condition)
}
else {
objectname = Left(condition, dot - 1)
attributename = Mid(condition, dot + 1)
object = GetObject(objectname)
if (object = null) {
result = false
}
else {
result = GetBoolean(object, attributename)
}
}
if (result = checkfor) {
return (ProcessTextSection(text, data))
}
else {
return ("")
}
}
else {
lhs = Left(condition, operator - 1)
rhs = Mid(condition, operator + operatorlength)
op = Mid(condition, operator, operatorlength)
dot = Instr(lhs, ".")
if (dot = 0) {
objectname = ""
attributename = ""
if (HasInt(game, lhs)) {
objectname = "game"
attributename = lhs
}
else {
return ("{if " + command + "}")
}
}
else {
objectname = Left(lhs, dot - 1)
attributename = Mid(lhs, dot + 1)
}
object = GetObject(objectname)
if (object = null) {
return ("{if " + command + "}")
}
else {
value = GetAttribute(object, attributename)
// Next three lines added by The pixie
if (TypeOf(value) = "object") {
value = value.name
}
if (op = "=") {
if (ToString(value) = rhs) {
return (ProcessTextSection(text, data))
}
else {
return ("")
}
}
else if (op = "<>") {
if (not ToString(value) = rhs) {
return (ProcessTextSection(text, data))
}
else {
return ("")
}
}
else if (op = ">") {
if (ToDouble(ToString(value)) > ToDouble(rhs)) {
return (ProcessTextSection(text, data))
}
else {
return ("")
}
}
else if (op = "<") {
if (ToDouble(ToString(value)) < ToDouble(rhs)) {
return (ProcessTextSection(text, data))
}
else {
return ("")
}
}
else if (op = ">=") {
if (ToDouble(ToString(value)) >= ToDouble(rhs)) {
return (ProcessTextSection(text, data))
}
else {
return ("")
}
}
else if (op = "<=") {
if (ToDouble(ToString(value)) <= ToDouble(rhs)) {
return (ProcessTextSection(text, data))
}
else {
return ("")
}
}
}
}
}


The only difference is an extra four lines, the first being a comment, that will convert an object (such as ball.parent) to a string ("room").

jaynabonne
19 Nov 2014, 22:59
I would love to see the "if" part of the text processor just use "eval" to allow any sort of expression. (But that's my pipe dream!)

Avantar
20 Nov 2014, 06:35
Thank you Pixie.
I am using TA.I will give it a shot. Else, I will just create an attribute with values indicating if the object was taken or not and amend the take section of the object. It will be awesome not having to do that.
@Jaynabonne: My first time looking at text processing and 'eval' is above me, but if means sorting out referencing objects in the text processor - I am with that suggestion

Avantar
20 Nov 2014, 07:12
@The Pixie
Great! So far it works a treat.
Thank you.

Avantar
20 Nov 2014, 10:14
One last question:
I was wondering if it is possible to execute a command from the text processor - Like {command:rolldice} Instead of giving the link just execute the command.

Thank you in advance.

jaynabonne
20 Nov 2014, 12:27
Do you mean a function? It seems odd to execute a command while in the middle of printing out text. What is the purpose?

(A function could be handy if you wanted to inject content at that point and the function returned a computed string.)

Avantar
20 Nov 2014, 12:33
I guess function. Got a command that is in any case calling the function - so I guess I meant function.
The reason is just to get the correct order of text, otherwise I would have called the function normally.

So when entering the room I want some statistics printed out from the player at the top and at the bottom I want an object link with options.
If the function is run when entering the room and I guess even before entering the room - The object link is just at the top or somewhere I do not want it.

Avantar
20 Nov 2014, 14:17
I got it working!