Can't use multiple functions in script?
-
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
-
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"); } -
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 -
Awesome work, thanks guys
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login