Skip to content
ryobg edited this page Feb 15, 2018 · 2 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 and relations between these entities. Though there is no way to create a custom entity in Papyrus, it is still possible to overcome that. For example:

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")
endfunction

All above is useless due to existence of Aliases, but not so mcuh 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)