Lokale Variablen in Funktionen

Alles rund um TX(T) und RoboPro, mit ft-Hard- und Software
Computing using original ft hard- and software
Forumsregeln
Bitte beachte die Forumsregeln!
tttttom
Beiträge: 11
Registriert: 11 Mai 2019, 11:27

Re: Lokale Variablen in Funktionen

Beitrag von tttttom » 23 Dez 2021, 09:07

So kann die Fehlermeldung noch einfacher erzeugt werden:
Unbenannt.PNG
Unbenannt.PNG (1.02 KiB) 1610 mal betrachtet
Das ist natürlich nicht sinnvoll, sollte meines Erachtens aber von RoboPro trotzdem fehlerfrei bearbeitet werden.

tttttom
Beiträge: 11
Registriert: 11 Mai 2019, 11:27

Re: Lokale Variablen in Funktionen

Beitrag von tttttom » 23 Dez 2021, 09:26

Back to topic of that thread: local variables in functions. My wish would be that:
Unbenannt.JPG
Unbenannt.JPG (11.27 KiB) 1605 mal betrachtet
Unbenannt.PNG
Unbenannt.PNG (1.93 KiB) 1605 mal betrachtet
But this produces no error and just does not work. Of course, I could use a workflow element. But for me, it is not obvious, that the time of existance of the local var is a problem...

Benutzeravatar
MasterOfGizmo
Beiträge: 2720
Registriert: 30 Nov 2014, 07:44

Re: Lokale Variablen in Funktionen

Beitrag von MasterOfGizmo » 23 Dez 2021, 09:28

Und wenn Du nur eines von den Var-Dingern nimmst und dessen Ausgang mit seinem eigenen Eingang verbindest?
Arduino für fischertechnik: ftDuino http://ftduino.de, ftDuino32 http://ftduino.de/32

ROBOProEntwickler
Beiträge: 14
Registriert: 28 Dez 2012, 14:56

Re: Lokale Variablen in Funktionen

Beitrag von ROBOProEntwickler » 28 Dez 2021, 14:37

tttttom hat geschrieben:
23 Dez 2021, 09:26
Back to topic of that thread: local variables in functions. My wish would be that:
ROBOPro has three scopes for variables and other entities like input, outputs, instances of subprograms, process starts, ...

- global: this means the variable exists always (from main program start to main program end). Please note that global variables can be linked by name so that a variable with the same name in different subprograms shares the same memory or it cannot be linked. This is intended to avoid name clashes with internal global variables of subprograms.

- local: this means the variable exists from subprogram entry to exit. in a subprogram without entry or exit, local variables never exist. These kind of local variables are similar to what you know from C - they live on a call stack, they are distinct in recursive calls and different threads.

- object (available in level 5 in the property menu of variables): this means the variable exists from the time of creation to deletion of the containing subprogram. When this is depends on how the subprogram is embedded in its containing subprogram - this can again be local, object or global.

What you want in "circuit style" subprograms without entry/exit are usually object or global variables, so that the variable exists once per instantiation of the block.

Please note that most entities have these scope options, notably also process starts. If you create a local process in a subprogram, the process gets killed as soon as the subprogram ends. This is quite useful to implement e.g. emergency stop functionality - the emergency stop exits a subprogram which contains all work processes as local processes.

That said, I don't think one needs any variables at all to write a minimum circuit block. The multiplexer examples in "Library/logic/multiplexer" show how to select values using and and or gates. Note that the and and or gates are 16 bit wide. The "-1" after the comparison changes the 0/1 output of the comparison gate to 0/-1 and -1 is all bits set.

ROBOProEntwickler
Beiträge: 14
Registriert: 28 Dez 2012, 14:56

Re: Lokale Variablen in Funktionen

Beitrag von ROBOProEntwickler » 28 Dez 2021, 15:04

tttttom hat geschrieben:
23 Dez 2021, 09:07
So kann die Fehlermeldung noch einfacher erzeugt werden:
Connecting the output to the input of a variable (variables with the same name and active "link by name" are like one variable block) leads to endless recursion in message sending, which then leads to a stack overflow. Certain input/output constructs have the same effect. This is by design and not considered a bug since there is no point in doing this and very few people actually do it accidentially.

Operators have recursion stoppers to avoid endless message recusion, since with operators in the loop it is more frequent that this happens accidentially.

ROBOProEntwickler
Beiträge: 14
Registriert: 28 Dez 2012, 14:56

Re: Lokale Variablen in Funktionen

Beitrag von ROBOProEntwickler » 28 Dez 2021, 15:10

P.S.: viel Spaß beim Cube Solver Roboter basteln - ganz zu Anfang von ROBOPro hat das schon mal jemand gemacht - allerdings noch ohne Kamera sondern mit fabrigen LEDs und Fotowiderstand zum Farbe scannen ...

vleeuwen
Beiträge: 1565
Registriert: 31 Okt 2010, 22:23
Wohnort: Enschede (NL)
Kontaktdaten:

Re: Lokale Variablen in Funktionen

Beitrag von vleeuwen » 29 Dez 2021, 00:53

Thanks ROBOProEntwickler for your clarification.
I like RoboPro very much
software enigineer/teacher/advisor
Google translate
http://tescaweb.nl/Carel/?p=713

Antworten