euddraft
euddraft copied to clipboard
epScript: typed var
what I want to write instead in epScript: (currently not possible)
function LarvaConnectHatch() {
const larvae = EUDDeque(3, CUnit)();
RemoveUnitAt(2, "Zerg Hatchery", "Anywhere", P2); // pre-overlap 3 Hatchery together
var hatchery: CUnit = 0; // static variable typed CUnit
foreach(cunit: EUDLoopPlayerCUnit(P2)) {
switch(cunit.unitType) {
case $U("Zerg Larva"):
larvae.append(cunit);
break;
case $U("Zerg Hatchery"):
hatchery = cunit; // here
break;
}
}
while (!larvae.empty()) {
const larva = larvae.pop();
larva.connectedUnit = hatchery;
}
}
It's possible to write this function in eudplib:
@EUDFunc
def LarvaConnectHatch():
larvae = EUDDeque(3, CUnit)()
DoActions(RemoveUnitAt(2, "Zerg Hatchery", "Anywhere", P2))
hatchery = CUnit.cast(EUDVariable(0)) # prevent copying variable
for cunit in EUDLoopPlayerCUnit(P2):
EPDSwitch(cunit + 0x64/4, 0xFF)
if EUDSwitchCase()(EncodeUnit("Zerg Larva")):
larvae.append(cunit)
EUDBreak()
if EUDSwitchCase()(EncodeUnit("Zerg Hatchery")):
hatchery << cunit
EUDBreak()
EUDEndSwitch()
if EUDWhileNot()(larvae.empty()):
larva = larvae.pop()
larva.connectedUnit = hatchery
EUDEndWhile()
- typed var hatchery: similar to
let mut hatchery: Option<CUnit>
- typed container (deque)
Currently var
in eps copys value to new variable, makes it untyped.
ExprProxy can proxy both const and var expression, so:
object Foo { var bar; };
var x = Foo(); // mutable variable with static object as initial value, typed `Foo`
function afterTriggerExec() {
x.bar; // Currently compile error (EUDVariable has no attribute 'bar') but planned to be allowed
x = 0; // Currently valid.
const y = Foo.alloc();
x = y; // Currently also valid
foreach(unit : EUDLoopCUnit()) {
unit += 336 / 4; // Currently this is valid but unit loses its type information (becomes EUDVariable)
unit.hp; // AttributeError: EUDVariable has no 'hp'
}
var varTypedFoo = x;
var untypedVar = 0;
var alsoUntypedVar = untypedVar;
var arrayVar = EUDArray(8);
arrayVar[0] += 1; // Currently compile error (EUDVariable has no len? Or EUDVariable has no setitem) but planned to be allowed
arrayVar = 0; // Currently valid
arrayVar[0] = 1; // this will raise 'Not supported EUD' error with error code 0xFFFFFFFF
}
To not introduce any breaking change, it's like putting implicit typecast at every mutation.