OpenKore / openkore

A free/open source client and automation tool for Ragnarok Online
http://openkore.com
Other
1.28k stars 1.04k forks source link

Whitespace sensitivity for EventMacro #3759

Open KoukatsuMahoutsukai opened 1 year ago

KoukatsuMahoutsukai commented 1 year ago
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."

VasilyGorborukov commented 1 year ago

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

macro 3{
    $i = 0
    while ($i < 10){
    log \$i = $i
    $i++
    }
}
KoukatsuMahoutsukai commented 1 year ago

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

LycorisRecoil-NishikigiChisato commented 1 year ago

@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++ } }`

KoukatsuMahoutsukai commented 1 year ago

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.

LycorisRecoil-NishikigiChisato commented 1 year ago

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

KoukatsuMahoutsukai commented 1 year ago

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.