Home AMX User Forum NetLinx Studio

Netlinx SFX (Episode 1: Hartbeat or stroke?)

Recently I was about to implement a simple hartbeat timeline as I usually do it. However, for some reason this time it didn't work out as expected. I took me quite some time to find the error in the code. That's why I added this error to my personal "hall of fame" of Netllinx unexpected behaviors (I call it "special effects" hence the titel "SFX"). Since maybe others may struggle as well, I'm proud to present you my newest SFX-member:

simplified code sample:
PROGRAM_NAME='NI-SFX'

DEFINE_CONSTANT

INTEGER _HB_TIMELINE = 1
INTEGER _HB_TIMEARRAY[] = { 10000 }


DEFINE_VARIABLE

volatile long _HB_COUNT = 0


DEFINE_START

IF(!(TIMELINE_ACTIVE(_HB_TIMELINE)))
{
    SEND_STRING 0, "'starting HB_TIMELINE (ID ',itoa(_HB_TIMELINE),')'"
    TIMELINE_CREATE(_HB_TIMELINE,_HB_TIMEARRAY,1,TIMELINE_ABSOLUTE,TIMELINE_REPEAT)
}


DEFINE_EVENT
TIMELINE_EVENT[_HB_TIMELINE]
{
    SEND_STRING 0, "'HB count=',itoa(_HB_COUNT)"
    _HB_COUNT = 0
}


DEFINE_PROGRAM
_HB_COUNT++

expected result:
...
Line     26 (10:42:07)::  CIpInterpreter::Run - Execute Startup Code
Line     27 (10:42:08)::  starting HB_TIMELINE (ID 1)
...
Line     49 (10:42:18)::  HB count=190291
Line     50 (10:42:28)::  HB count=193749
Line     51 (10:42:38)::  HB count=193674
Line     52 (10:42:48)::  HB count=193626
Line     53 (10:42:58)::  HB count=193685
...

real result:
...
Line     23 (10:42:07)::  CIpInterpreter::Run - Execute Startup Code
Line     24 (10:46:56)::  starting HB_TIMELINE (ID 1)
Line     25 (10:46:56)::  CIpTimeline::Create - Error 2
...

So, what's wrong with this code? The first correct answer earns prise and honor (sorry: no free NI or something.... ;-)
Patrick

Comments

  • INTEGER _HB_TIMEARRAY[] = { 10000 }

    should be;

    LONG _HB_TIMEARRAY[] = { 10000 }
  • wengerpwengerp Posts: 29
    Wow, that was fast. It took me definitely longer to figure it out. Congrats!
    Patrick
  • wengerpwengerp Posts: 29
    BTW: wouldn't this be worth a compiler warning?
Sign In or Register to comment.