PDA

View Full Version : filtering listener feedback


groutcho
01-15-2009, 01:37 PM
Is it possible to filter the listener's feedback to remove "OKs" and variable values returns ? the Clearlistener() function is okay but only for the beginning of the script execution. I would like to clear the listener during the execution of the script without removing useful strings.

I would like to print an array in the listener and i wouldn't want to be annoyed with parasite feedback.

Another question : why in the listener some feedback is duplicate (e.g the same return value is displayed twice)

Thanks in advance

diffx
01-15-2009, 01:48 PM
As for question 2: this can be caused by the fact that the listener prints the result of the last line in the script. Thus, a print command at the end of your script prints it twice.

(
x = "Last line of my script"
)

Result:
Last line of my script

(
x = "Last line of my script"
print x
)

Result:
Last line of my script
Last line of my script

Same happens if you use a print command in the listener.

groutcho
01-15-2009, 01:51 PM
Thanks, one annoying problem removed !

Bobo
01-15-2009, 02:53 PM
Well, you should NEVER run your code in global scope anyway.
So if you start your code with ( and end it with ), nothing will be printed except the return value UNLESS you use Print() or format() to output whatever YOU want to it. For example

(--start local scope
a = 10
b = 20
c = a + b
print c
d = c*2
OK
)--end script

The output will be

30
OK

Without the OK at the end, it would output

30
60

because 60 is the last value calculated within the scope and is output as the return value of the whole expression.

If you remove the brackets and evaluate in global scope (BAD idea!),

a = 10
b = 20
c = a + b
print c
d = c*2

the output would be

10
20
30
30
30
60
OK

Note that 30 is the return value of 'c=a+b', the side effect of the 'print c' call and the return value of the 'print c' call, so it appears THREE times in global scope, but just once as side effect of the 'print c' call in the local scope.

At this point, the variables a, b, c and d are GLOBAL and could affect code which uses the same variable names in local scope without an explicit LOCAL declaration. In other words, you would be polluting the global scope with variables that could be used somewhere else and affect code you don't even know about. Thus, using long descriptive names for global variables is a must!

groutcho
01-15-2009, 04:24 PM
Well, you should NEVER run your code in global scope anyway.
So if you start your code with ( and end it with ), nothing will be printed except the return value UNLESS you use Print() or format() to output whatever YOU want to it.

It was just a draft, the final code is integrated in a macroscript, but I didn't know that you could create a code block (and its scope) just by putting it between parentheses without the need of a function or loop or conditional statement. That sure is a great thing to know !

Thanks for the great explanation mister Bobo :applause:

CGTalk Moderation
01-15-2009, 04:24 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.