Script editor - setting values inside logical statements

is there a way to set values to items inside logical statements when using script editor?

example:
eventhandler is visionWindowOpened
....
if myTag == 1
myvisionComponent.blink = 1
...

You have to pass myvisionComponent as an object into your script function, usually as a function argument, if you aren't in a script context that automatically supplies the object. Script contexts vary greatly.

Which script editor are you working in?

Quite new - so unsure of editor name. I would guess Component scripter. Here is image.

I can access to the object I want but the if statement fails.

I am guessing by design the return value from case, if etc returns the value to the binding.

So, Vision Event context. Vision events have an event object and system and any library scripts preloaded in local scope. In the lower right, you have a summary of what is provided in that particular event's event object.

Pretty much all Vision events provide event.source, which is a window in this case. From which you can obtain the root container object and/or lookup components by path.

Vision events don't use any return value.

Don't confuse expression bindings with scripts.

Also note the comment about when this event runs: Window open is rarely the right time to manipulate components.

Please explain what you are trying to do.

Once a screen is opened I want to highlight an area by changing colour and than back to original colour.

I have been able to figure out the changing colour portion using "invokelater". Struggling with the conditional part which would allow highlight different component depending on user selection prior to opening the screen.

Might be able to do this with property binding instead - just reading about it now.

The script is failing to compile because the if statement is missing its colon. It should be written like this:

# include a colon at the end
if event.source.rootContainer.getComponent('label 14').text == '18xjhw9':
	# Do stuff here

Also, there is no way to guarantee that the label will exist when the visionWindowOpened event fires. It would be better to use internalFrameOpened or the label's componentRunning property change event.

Thanks @justinedwards.jle. Yeah having the colon fixed it.

In regards to the label existing or not. Why would it not be there? It is an object that doesn't have visibility biding.

Also, would you not want internalFrameActivated? Screen could be cashed.

I would not use internalFrameActivated for initialization because if the user clicks away from the desktop, the internal frame will deactivate, and the internalFrameActivated script will run again when the user comes back.

visionWindowOpened happens before internalFrameOpened, and the label exists in the internal frame. Several times I've seen problems in the forum that were ultimately fixed by simply moving an initialization script from window opened to internal frame opened.

I rarely use internal frame opened anymore. I prefer to use a component's property change event handler to call my component initialization scripts from the componentRunning event.

1 Like