Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions
Options

stupid problem with "if" and "else"

Hi @all,
i need a solution to send the time to my ******** system.
Normaly no problem to do it mayby 2 times a minute. But the variable "Zaehler" stays with the value 20 (seen in debugger)
What the hell is wrong?
It seems so easy....
thanks
Martin


Here parts of the code:

DEFINE_VARIABLE

Seite
UseWeckzeit
UseRollozeit
Zaehler

DEFINE_PROGRAM

(* + + + + Impulsgeber + + + + + + + + + + + + + + + + + + + + + + *)

IF(Zaehler>=20)
{
SEND_STRING ********,"'12345'""__TIME__,$0D"
Zaehler=1
}

ELSE

{
Zaehler=Zaehler+1

}

(* + + + + + + + + + + + + + + + + + + *)

Comments

  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    Try this:
    DEFINE_VARIABLE
    
    Seite
    UseWeckzeit
    UseRollozeit
    Zaehler
    
    DEFINE_PROGRAM
    
    (* + + + + Impulsgeber + + + + + + + + + + + + + + + + + + + + + + *)
    WAIT 1200 {
       SEND_STRING ********,"'12345',TIME,$0D"
    }
    (* + + + + + + + + + + + + + + + + + + *)
    

    Because you have the statement in DEFINE_PROGRAM, it is running very often (I would guess at least 300 times per second). Also, the time you are sending is the time when you compiled your program, not the current time. By putting everything in a wait statement, the program tracks the wait and will only create a single SEND_STRING every 2 minutes.

    Jeff
  • Options
    a_riot42a_riot42 Posts: 1,624
    I can assure you your problem isn't with if or else.
  • Options
    Hi, sorry for the delay...

    @a_riot42
    This way works, but why?

    (* + + + + Impulsgeber + + + + + + + + + + + + + + + + + + + + + + *)
    IF(Zaehler=400)
    {
    Zaehler=1
    }
    ELSE
    {
    Zaehler=Zaehler+1
    }
    (* + + + + + + + + + + + + + + + + + + *)
    IF(Zaehler=2)
    {
    SEND_STRING ********,"'AMX-Zeit ',time,$0D"
    }

    @Spire_Jeff
    Thanks for thr hint 'bout __Time__ and Time....
    The "wait" will be maybee one of the final solutions but I will find out what's wrong? In Basic (1981) I've had no problems....
    Regards
    Martin
  • Options
    viningvining Posts: 4,368
    siegburger wrote:
    Normaly no problem to do it mayby 2 times a minute. But the variable "Zaehler" stays with the value 20 (seen in debugger)
    Spire_Jeff wrote:
    Because you have the statement in DEFINE_PROGRAM, it is running very often (I would guess at least 300 times per second).

    I would think you'd see other numbers ocassionally in the debugger but it's counting so fast debugger can't keep up and if it could then your eyes couldn't.
    (* + + + + Impulsgeber + + + + + + + + + + + + + + + + + + + + + + *)
    IF(Zaehler=400)
    {
    Zaehler=1
    }
    ELSE
    {
    Zaehler=Zaehler+1
    }
    (* + + + + + + + + + + + + + + + + + + *)
    IF(Zaehler=2)
    {
    SEND_STRING ********,"'AMX-Zeit ',time,$0D"
    }
    
    This code is dependant of how often your processor runs through the main line and it will vary depending on what's going on in your system so it's really not a proper way of timing at all if that is indeed what you're trying to accomplish. If you actually want to count main line passess then this should be fine but if you actually want to send a string every minute or two the wait is the simple and likely the most efficient way to go.

    Now if your master actually does run through the main line around 300 x per second which I think is probably a good estimate then you are going to be sending your string every 1.25 second or there abouts which is another burden your system could do with out. Your 1st version was so fast I'm suprised it didn't bring your system to a crawl trying to send strings 15 times per second.
Sign In or Register to comment.