-
Notifications
You must be signed in to change notification settings - Fork 38
Let's play in OOP
SilverIce edited this page May 18, 2015
·
10 revisions
OOP is a way of thinking in the Object Oriented Way, the way of modelling to represent your code as a set of entities, their behaviour, relations between entities. Though there is no way to create a custom entity in Papyrus, it's still possible to outcome that. It's simpler to show how:
Scriptname Pet Hidden
import JMap
int function petWithNameAge(string sname, int iage, string stype) global
int jpet = object()
setName(jpet, sname)
setInt(jpet, "age", iage)
setType(jpet, stype)
return jpet
endfuction
string function name(int jpet) global
return getStr(jpet, "name")
endfunction
function setName(int jpet, string sname) global
setStr(jpet, "name", sname)
endfunction
string type(int jpet) global
return getStr(jpet, "type")
endfunction
;;;;;;;;
Scriptname Wolf extends Pet Hidden
import JMap
import Pet
int function wolfWithNameAgeColor(string sname, int iage, int icolor) global
int jpet = petWithNameAge(sname, iage, "Wolf")
setType(jpet, "Wolf")
setColor(jpet, icolor)
return jpet
endfuction
int function color(int jpet) global
return getInt(jpet, "color")
endfunction
function setColor(int jpet, int icolor) global
setInt(jpet, "color", icolor)
endfunction
;;;;;;;;;;;;;
Scriptname Owner Hidden
import JMap
int function ownerWithPet(int jpet) global
int jo = object()
setObj(jo, "pet", jpet)
return jo
endfunction
int function pet(int jo) global
return getObj(jo, "pet")
endfunctionThe example above is useless due to existence of Aliases, but not as useless in case of other, more abstract entities (like a Color). The entities are: Owner, Wolf. Owner owns a Pet:
int wlf = Wolf.createWithNameAgeColor("Akella", 4, 0x12456)
int ownr = Owner.create()
Owner.ownPet(ownr, wlf)Sign into GitHub and press Edit at the top to add any missing information or fix typos and errors. Thanks!