Passing variables in scripting

Discuss issues and ideas you have to configuring displays with PowerVision
cconner_aie
Posts: 93
Joined: Thu Jun 11, 2015 10:12 am

Passing variables in scripting

Post by cconner_aie » Tue Nov 29, 2016 4:21 pm

I'd like to split up some of my code in scripts but for some reason my script will hang if I try to pass variables. E.G.

Code: Select all

void $functionOne$()
{
	int aVariable = 0;
	smRead(VariableIDs.A_VARIABLE, aVariable);
	
	functionTwo(aVariable);
}

void functionTwo(int aVariable)
{
	// blank
}
The above will fail to run, as will this:

Code: Select all

void $functionOne$()
{
	
	functionTwo(0);
}

void functionTwo(int aVariable)
{
	// blank
}
However, this runs fine:

Code: Select all

void $functionOne$()
{
	int aVariable = 0;
	smRead(VariableIDs.A_VARIABLE, aVariable);
	
	functionTwo();
}

void functionTwo()
{
	// blank
}
which makes me assume we are not allowed to pass variables, which would be rather silly as that limits a key feature in using functions and this was pulled directly from the Scripting Syntax Reference:

Image

So it would seem AngelScript allows you to do this, am I doing something wrong or can we not pass variables into a function with what ever version of AngelScript is implemented in PowerVision? Hopefully it's apparent this isn't my actual code, but functionally it works the same. I can provide the whole script or a project file if you'd like.

Thanks,
Coleby Conner
Controls Engineer, Anderson Industrial Engines
stalley
Enovation Controls Development
Enovation Controls Development
Posts: 618
Joined: Tue Mar 18, 2014 12:57 pm

Re: Passing variables in scripting

Post by stalley » Tue Nov 29, 2016 4:45 pm

Hi Coleby,

You can do it. I'm not sure how you determine that it isn't working. I'm sending a config that reads a database variable to a local, passes the local to a different function, increments the passed in variable then writes to the database variable. This is probably an oversimplification of what you are trying to do, but maybe it will help you find what is going wrong.

Press the top right button to fire the event.

How is this different from what you are doing?
Attachments
cconner_aie function with parameter.zip
(688.08 KiB) Downloaded 17 times
Sara Talley
Software Engineer
Enovation Controls
cconner_aie
Posts: 93
Joined: Thu Jun 11, 2015 10:12 am

Re: Passing variables in scripting

Post by cconner_aie » Thu Dec 01, 2016 10:33 pm

Hmm...

While downloading 2.8 patch 3 to open your example I created a blank configuration and tried again and it did indeed work. I modified the code from when I originally asked so I'm not sure what I was doing wrong. Probably a semi-colon missing somewhere or something else equally dumb.

Thanks for your help.
Coleby Conner
Controls Engineer, Anderson Industrial Engines