armoha / euddraft

System for pluginizing eudplib codes.
Other
29 stars 4 forks source link

Should we allow implicit conversion from Condition to bool? #43

Closed armoha closed 9 months ago

armoha commented 2 years ago

Ofc we don't have bool type yet.

Summary of unusual Condition usages:

  1. Caching
    var upnum, charge;
    const cache3051 = MemoryXEPD(3051, Exactly, 0, 15);
    if (!cache3051) {
    // these triggers only run once upgrade level 'changes'
    const up3051 = maskread_epd(3051, 15);
    SetMemory(cache3051 + 8, SetTo, up3051);
    upnum = up3051 * 3333;
    charge = upnum << 8;
    }
    
    const array = EUDArray(8);

const s = StringBuffer(); const cache1 = Accumulate(CurrentPlayer, Exactly, ~0, Ore); const cache2 = Bring(CurrentPlayer, Exactly, ~0, "Artanis", "loc"); const cache3 = MemoryEPD(EPD(array) + cp, Exactly, ~0); if (cache1 && cache2 && cache3) {} else { const my_mineral = dwread_epd(EPD(0x57F0F0) + cp); const arta_count = EUDBinaryMax(function(x) { return l2v(Bring(CurrentPlayer, Exactly, x, "Artanis", "loc")); }, maxv=1700); const array_cp = array[cp]; SetMemory(cache1 + 8, SetTo, my_mineral); SetMemory(cache2 + 8, SetTo, arta_count); SetMemory(cache3 + 8, SetTo, array_cp); s.insert(0); s.append("This text only updates when any of these changes; ore ({}), Artanis count ({}), array member ({})", my_mineral, arta_count, array_cp); } s.Display();


2. Multiple conditions
```js
var a = (A == B) && (C == D) && (E == F);  // OK

Failed usages:

  1. Condition arithmetics

    var x = (v == 0) * 10;  // Error: Orphan condition. This often happens when you try to do arithmetics with conditions.
    var x = l2v(v == 0) * 10;  // OK
  2. Return condition

    function f() {
    return v > 1;  // Error: Orphan condition. This often happens when you try to do arithmetics with conditions.
    return l2v(v > 1);  // OK
    }

Orphan condition error due to eudplib's low-level-ness

(WIP) For users, orphan condition error is hard to fix; error raises in late phase, and error message does not tell where the errorneous code is.

Potential ambiguity if we allow condition arithmetics

var x = (v >= 2) + 1;
// what should x be? 1 or 2 depends on evaluation? or Condition address + 1?
armoha commented 9 months ago
var a = (A == B) && (C == D) && (E == F);  // OK
var b = (A == B);  // orphan condition error

We won't fix second case to work, so IMO both syntaxes should be disallowed as well for consistency. (This would break some EUD Editor codes btw...)