Hi!
Stehe mal wieder mit meinem Latein vor einer Mauer:
Ich möchte in einer Funktion einen Static - Wert quasi als Default initialisieren, aber des weiteren umändern. Dabei wird die Funktion immer wieder aufgerufen. Hat da jemand eine Idee für mich?
Per Code sieht das inetwa so aus:
WHILE TRUE
bla()
WEND
FUNCTION bla:
STATIC hui
hui = Veränderung
ENDFUNCTION
Oder zumindest so ähnlich!
GLB
W.
Hmm, ich hoffe ich hab das verstanden.
WHILE TRUE
bla(0)
WEND
FUNCTION bla:pos = 0
STATIC hui AS m
RETURN hui.a[pos] = veraenderung
ENDFUNCTION
TYPE m
a[10]
ENDTYPE
If you want to initialize the value on first run, make a new static that you never change in the code so when the routine starts you can be sure that the value will be 0 on first run. Then init the variable you want and then set first_time to 1 or whatever.
WHILE TRUE
bla()
WEND
FUNCTION bla:
STATIC hui, first_time
if first_time = 0
hui = 42 // init
first_time = 1
endif
hui = Veränderung
ENDFUNCTION
Great! Thank you! =D
If you assign something to a static, then the first time it is used this value gets assigned:
poo()
poo()
poo()
FUNCTION poo:
STATIC c = 5
DEBUG c + "\n"
INC c, 1
ENDFUNCTION
Output:
5
6
7
this only works if it is a number or string, cant init with a return value from a function or similar. So I preffer to be safe, when I was using static init the other way my program would work and then stop working on the next update :-)