ItsDeltin / Overwatch-Script-To-Workshop

Converts scripts to Overwatch workshops.
207 stars 24 forks source link

Raising a negative number to the power of a variable compiles to a 0 #379

Closed WesselvanGils closed 2 years ago

WesselvanGils commented 2 years ago

Exactly as the title says,

If you take any negative number and use ^ to raise it to the power of a variable the result will compile to be 0

steps to reproduce:

  1. Create a script that look something like this:
playervar define Ticker;

rule: " Example "
Event.OngoingPlayer
{
    LogToInspector( -2 ^ Ticker);
}
  1. Compile to workshop code using the VsCode extension and executing "create panel for workshop code output"

the result should look like this:

variables
{
    player:
        0: Ticker
}

rule(" Example ")
{

    event
    {
        Ongoing - Each Player;
        All;
        All;
    }

    // Action count: 1
    actions
    {
        Log To Inspector(0);
    }
}
ItsDeltin commented 2 years ago

This is because the Overwatch workshop returns zero when raising a negative value to a power: -2^2 = 0. This should give the behavior you are looking for, if Ticker will always be a whole number: 2 ^ Ticker * (Ticker % 2 == 0 ? 1 : -1)