openkore icon indicating copy to clipboard operation
openkore copied to clipboard

Whitespace sensitivity for EventMacro

Open KoukatsuMahoutsukai opened this issue 2 years ago • 6 comments

  • Openkore version git: Latest
  • Server: Private server
  • Bug Report / Feature Request: Whitespace sensitivity for EventMacro
  • Summary: Just wondering if the Flow control statements are intended to be whitespace sensitive? the macro 1,2 and 3 below would behave differently after all. if its intended then neverminded me, if its not I can take a look at it further, might be a problem with the regex?
macro 1{
	$i = 0
	while($i < 10) {
	log \$i = $i
	$i++
        )
}

macro 1 would do the first iteration and print out a $i = 0, then would proceed to break out of the while loop, when i turn on the debug messages i would get these at the end [eventMacro] Script '}'. [eventMacro] Script is the end of a not important block (if or switch).

macro 2{
	$i = 0
	while ($i < 10) {
	log \$i = $i
	$i++
        }
}

macro 2 would work as intended, logging 1 to 10.

macro 3{
	$i = 0
	while ($i < 10){
	log \$i = $i
	$i++
        }
}

And macro 3 would outright crash the openkore and would output a message of "The error message is: Modification of non-creatable array value attempted, subscript -1 at plugins/eventMacro/eventMacro/Runner.pm line 1421."

KoukatsuMahoutsukai avatar Jun 02 '23 13:06 KoukatsuMahoutsukai

You forgot about the second "}". For Example:

macro 3{
	$i = 0
	while ($i < 10){
	log \$i = $i
	$i++
	}
}

VasilyGorborukov avatar Jun 03 '23 06:06 VasilyGorborukov

yeah sorry for that typo, results stay the same fortunately/unfortunately.

KoukatsuMahoutsukai avatar Jun 03 '23 06:06 KoukatsuMahoutsukai

@KoukatsuMahoutsukai macro 3{ $i = 0 while ($i < 10){ log \$i = $i $i++ } }

For example: while ($i < 10) { } O while($i < 10) { } X while ($i < 10){ } X while($i < 10){ } X while ( $i < 10 ) { } X macro 3{ } X

" " Blank space between program statements is very important. The lack of blank space will make the statement unrecognizable. Correct: macro 3 { $i = 0 while ($i < 10) { log \$i = $i $i++ } }

Thank you for elaborating on the points I raised. My main concern with it is if it was intended since not all programming languages are inherently whitespace sensitive,

From my understanding the macro syntax undergoes regex transformation into Perl code through the plugin right? The plugin was designed to provide a pseudo code-like syntax, making it more user-friendly for non-technical users if I'm not wrong. However, the current whitespace sensitivity seems incongruent with this objective. Additionally, I couldn't find any mention of this sensitivity to spacing in the documentation. Although the examples here are of what works and what doesn't work.

KoukatsuMahoutsukai avatar Jun 03 '23 13:06 KoukatsuMahoutsukai

Thank you for elaborating on the points I raised. My main concern with it is if it was intended since not all programming languages are inherently whitespace sensitive,

From my understanding the macro syntax undergoes regex transformation into Perl code through the plugin right? The plugin was designed to provide a pseudo code-like syntax, making it more user-friendly for non-technical users if I'm not wrong. However, the current whitespace sensitivity seems incongruent with this objective. Additionally, I couldn't find any mention of this sensitivity to spacing in the documentation. Although the examples here are of what works and what doesn't work.

The wiki has detailed usage: https://openkore.com/wiki/macro_plugin

I have read that and it has indeed detailed explanations but nowhere does it mention it is whitespace sensitive for Flow controls and labels, Also the macro plugin is different from the eventMacro plugin https://openkore.com/wiki/eventMacro.

the example you gave:

macro 3 {
	 $i = 0
	 while ($i < 10) {
	    log \$i = $i
	    $i++
           }
 }

wouldn't work at all with macro plugin since it has a different syntax, below is how while loops are used with macro plugin

macro while {
   $i = 0
   while ($i < 10) as loop
   log \$i = $i
   $i++
   end loop
}

And again my concern with it is if it was intended or not.

KoukatsuMahoutsukai avatar Jun 04 '23 07:06 KoukatsuMahoutsukai