mirror of
https://github.com/polserver/polserver
synced 2026-08-13 08:23:08 -04:00
* Add escript guide docs for classes * Add ClassInstanceRef to objref docs * Use objref.dot to generate svg
35 lines
695 B
Text
35 lines
695 B
Text
class Person()
|
|
function Person( this, name )
|
|
this.name := name;
|
|
endfunction
|
|
|
|
function Say( what )
|
|
Print( what );
|
|
endfunction
|
|
endclass
|
|
|
|
class Wizard( Person )
|
|
function Wizard( this, name )
|
|
super( name );
|
|
endfunction
|
|
|
|
function Attack( this )
|
|
Say( $"{this.name} casts a spell!" );
|
|
endfunction
|
|
endclass
|
|
|
|
class Fighter( Person )
|
|
function Fighter( this, name )
|
|
super( name );
|
|
endfunction
|
|
|
|
function Attack( this )
|
|
Say( $"{this.name} swings a sword!" );
|
|
endfunction
|
|
endclass
|
|
|
|
var gandalf := Wizard( "Gandalf" );
|
|
var aragorn := Fighter( "Aragorn" );
|
|
|
|
gandalf.Attack(); // Output: Gandalf casts a spell!
|
|
aragorn.Attack(); // Output: Aragorn swings a sword!
|