Can't use multiple functions in script?

Started by Millenium7, December 11, 2019, 06:16:49 AM

Previous topic - Next topic

Millenium7

This is not working

I create this as a script called SetInitialAttributes, it compiles and saves just fine no errors
// Set initial device attributes
// If an attribute does not exist, will create it with -1 as value
// If attribute already exists, will not change it


sub AirFiber()
{
if (GetCustomAttribute($node,"TestVar1") == null) SetCustomAttribute($node,"TestVar1",-1);
}

sub AirMax()
{
if (GetCustomAttribute($node,"TestVar2") == null) SetCustomAttribute($node,"TestVar2",-1);
}


Then I try and execute a function. I start off by testing with this

use SetInitialAttributes;
AirFiber();


Works fine

Then I try

use SetInitialAttributes;
AirMax();


And I get "Error 1 in line 13: Data stack underflow"
I tried switching the functions around so that AirMax() is on top i.e.

// Set initial device attributes
// If an attribute does not exist, will create it with -1 as value
// If attribute already exists, will not change it


sub AirMax()
{
if (GetCustomAttribute($node,"TestVar2") == null) SetCustomAttribute($node,"TestVar2",-1);
}

sub AirFiber()
{
if (GetCustomAttribute($node,"TestVar1") == null) SetCustomAttribute($node,"TestVar1",-1);
}



And it works fine when I call AirMax() because its the first function. But then I try calling AirFiber() and I get the same thing, error on line 13 data stack underflow

Am I doing something wrong? Is it not possible to use more than 1 function in a single script?

edit: I think this might be a bug. If I remove the 'SetCustomAttribute' command from both functions and replace it with something like 'println "test";' then I can run both functions just fine. But if I use 'SetCustomAttribute' in the 2nd function it causes the data stack underflow error. I can place lots of 'SetCustomAttribute' commands in the first function and they all run just fine, but when there's 2+ functions and running it on anything other than the first function causes this error

Alex Kirhenshtein

Yes, it's a bug, looks like automatic cast not working correctly in set custom attribute. Wrap -1 in quite marks and it will work.

// Set initial device attributes
// If an attribute does not exist, will create it with -1 as value
// If attribute already exists, will not change it


sub AirFiber()
{
if (GetCustomAttribute($node,"TestVar1") == null) SetCustomAttribute($node,"TestVar1","-1");
}

sub AirMax()
{
if (GetCustomAttribute($node,"TestVar2") == null) SetCustomAttribute($node,"TestVar2","-1");
}

Victor Kirhenshtein

Just fixed this. Bug is actually in source code parser - it is not related to custom attributes but rather to negative constant passed as function parameter. Fix will be included into next patch release.

Best regards,
Victor

Millenium7