Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. Can't use multiple functions in script?

Can't use multiple functions in script?

Scheduled Pinned Locked Moved Support
4 Posts 3 Posters 8.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    M
    Millenium7
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • A
      A
      Alex Kirhenshtein
      wrote on last edited by
      #2

      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");
      }
      
      1 Reply Last reply
      0
      • V
        V
        Victor Kirhenshtein
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • M
          M
          Millenium7
          wrote on last edited by
          #4

          Awesome work, thanks guys

          1 Reply Last reply
          0

          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
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          Powered by NodeBB Contributors
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups