The command 'once' is not doing what is expected
Forums › ProRealTime English forum › ProBuilder support › The command 'once' is not doing what is expected
- This topic has 9 replies, 3 voices, and was last updated 6 years ago by Vagus_Lux.
-
-
05/23/2018 at 10:17 AM #71154
Please try out following lines
123456Defparam DRAWONLASTBARONLY = TRUEM1 = Barindexonce M2 = M1DRAWTEXT("M1=#M1#", BarIndex[1], 0.1)DRAWTEXT("M2=#M2#", BarIndex[1], -0.1)ReturnI would expect that M2 is getting the value of M1 but the value stays zero!
05/23/2018 at 10:26 AM #71158It DOES do what it is expected from it!
That’s because ONCE is executed only ONCE; when you launch that code BARINDEX=0, so will be M1 and, finally… M2, which will NEVER be executed again (while M1 continues growing).
05/23/2018 at 12:39 PM #7116805/23/2018 at 1:14 PM #71175Not sure why it does not pick up the value but you do not really need the once. This code will fix the value as you want it. The Once is not necessary if you use an =
12345if barindex = 3 thenM2 = Barindexendifreturn M2 as "M2", barindex as "BarIndex"p.s. – it is preferred if you use the ‘Insert PRT Code’ button when posting code in the forums. I’ve tidied up your posts for you!
1 user thanked author for this post.
05/23/2018 at 2:13 PM #71182ONCE is read by the system ONCE at launch time, so your code could be written as
12345M1 = barindexif barindex >2 then//once M2 = M1endifreturn M2When BarIndex is ZERO the IF…ENDIF block will be skipped, later, when executed, line 3 will be skipped because of the ONCE keyword.
05/23/2018 at 2:15 PM #71183Thanks for your alternative code. You are right there are often many ways around. My sample code had to discover the missfunction of the command ‘once’ just in principle and my hope is to get it working in future. It was thought as a request to the programmer. I obvioused that the missfunction is limited to barindex but it works fine with other values.
05/23/2018 at 2:17 PM #71185ONCE is read by the system ONCE at launch time
Which so obviously why it does not work at BarIndex 3! I must be tired….
05/23/2018 at 2:27 PM #71187Do I get it right that ONCE is executed just one time in the very first loop of a program? So that it is not useful to use ONCE it in a later loop independent on its position? Thanks for your support to getting a better understanding.
05/23/2018 at 2:31 PM #71188ONCE is used to initialize a variable (PRT doeas not tell between variables and constants), as soon as the code is launched, after that it will simply be ignored, no matter where you write it.
05/23/2018 at 2:47 PM #71190 -
AuthorPosts