- Joined
- Jul 10, 2007
- Messages
- 6,306
private Type parent
When ya'll get better at coding, you'll see its use. Until then, debating its use is pointless =).
// Base types
globals
Type DAMAGE_TYPE_DPS
Type DAMAGE_TYPE_SLOW
endglobals
globals
Type DAMAGE_TYPE_FIRE
Type DAMAGE_TYPE_POISON
Type DAMAGE_TYPE_ICE
Type DAMAGE_TYPE_FROST
Type DAMAGE_TYPE_MUCK
endglobals
private module Init
private static method onInit takes nothing returns nothing
set DAMAGE_TYPE_DPS = Type.create(0)
set DAMAGE_TYPE_SLOW = Type.create(0)
set DAMAGE_TYPE_FIRE = Type.create(DAMAGE_TYPE_DPS)
set DAMAGE_TYPE_POISON = Type.create(DAMAGE_TYPE_DPS)
set DAMAGE_TYPE_ICE = Type.create(DAMAGE_TYPE_SLOW)
set DAMAGE_TYPE_FROST = Type.create(DAMAGE_TYPE_SLOW)
set DAMAGE_TYPE_MUCK = Type.create(DAMAGE_TYPE_SLOW)
endmethod
endmodule
private struct InitS extends array
implement Init
endstruct
this
this
as an index.Thanks for this writeup on this. I still don't understand how custom extensions are actually possible, as it should only be possible from the compiler side, but meh, it doesn't really matter if it works. ^^Structs compile like this:
- Static methods become regular functions
- Static variables become global variables
- Methods become functions that take an integer calledthis
- Variables become global array variables that usethis
as an index.
- Static method operators and method operators are treated like static and non-static methods.
- Modules just CnP the code they have inside them in the struct before everything compiles. Thankfully, Vexorian assured that a module will only be implemented once per struct. (No duplicate code, wee /o/)
- If the struct does not extend an array, you'll have generated allocate() and deallocate(integer) methods. Allocate compiles to a function that returns a unique integer and deallocate will compile to a function that takes an integer representing the instance to be deallocated and returns nothing.
- When inheritance comes into play, it's about either sharing functions or copying them.
That's all I can come up with on the spot. I might be wrong about something and I might have left something out. (I know I left out delegates and interfaces for one)
It would also be pretty need for things like buff systems.Seems cool...
Seeing Maggy's example, I could imagine lots of possible things with this... Maybe I'll have a use for this when I decide to go back to making maps... Probably for creating additional things to damage systems and such...
if (damageType.extends(DamageType.MAGIC)) then
it works like an array, remember also that you can store different object types to an array...This has nothing to do with arrays :|
set hero[0] = 'Hpal'
set hero[1] = 'Hamg'
set hero[2] = 'Hkmg'
set d[0] = DAMAGE_TYPE_FIRE
set d[1] = DAMAGE_TYPE_COLD
What battle?Spinnaker said:Almia lost in battle