Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick feature overview

Quick (and incomplete) feature overview

Note that this is not the documentation and the code below shows only ~25% of the functionality.

Generic array (JArray) manipulations

int a = JArray.object()
JArray.addInt(a, 0)
JArray.addForm(a, Game.GetPlayer())
JArray.addStr(a, "wow")

Actor player = JArray.getForm(a, 1) as Actor

string wow_str = JArray.getStr(a, -1)
str = JArray.getStr(a, 2)

JArray.setInt(a, 0, JArray.getInt(a, 0) + 1)

Dictionary (JMap or JFormMap, JIntMap) manipulations

int m = JMap.object()
JMap.setForm(m, "money", Game.GetFormFromFile(0xff))
JMap.setFlt(m, "amount", 10)
float amount = JMap.getFlt(m, "amount")

int keyHandler = JIntMap.object()
JIntMap.setStr(0x101, "KEY_X")

Store and read values on forms:

Actor plr = Game.GetPlayer()

JFormDB.setInt(plr, ".mslVampiricThirst.blood", plr.GetAVPercent("Health"))
JFormDB.setInt(plr, ".mslVampiricThirst.bloodMax", 100)
Form[] spells = ...
JFormDB.setObj(plr, ".mslVampiricThirst.spells", JArray.objectWithForms(spells ))

int bloodPoints = JFormDB.getInt(plr, ".mslVampiricThirst.blood")

Store and read values (globally):

string function configPath() global
  return "./Data/AutoSaverConfig.json"
endfunction

function readConfig() global
  int config = JValue.readFromFile(configPath())
  JDB.setObj("autosaver", config)
endfunction

float function getEventWeight(string event_) global
  return JDB.solveFlt(".autosaver.eventWeights."+event_)
endfunction

function setEventWeight(string event_, float v) global
  JDB.solveFltSetter(".autosaver.eventWeights."+event_, v, true)
endfunction

Common (JValue) functionality

-- some ridiculously complex data structure
int m = JValue.objectFromPrototype("[[[[[42]]]]]")

int two = JValue.count(m)
-- deepCopy will copy all objects
int clone = JValue.deepCopy(m)
-- shallowCopy will copy outer object only - the `m`, but not nested arrays
int shallowClone = JValue.shallowCopy(m)

Dump data structure into a file

int m = JMap.object()
JMap.setForm(m, "money", Game.GetFormFromFile(0xff))
JMap.setFlt(m, "amount", 10)
JValue.writeToFile(m, "map.json")

And "map.json" will contain:

{ "money": "__formData|Skyrim.esm|0xff", "amount": 10 }

Read the data back and put into new container

int newMap = JValue.readFromFile("map.json")

Multidimensional arrays:

-- construct 8x8 array
int cells = JArray.object()
int dim = 8
while dim > 0
  dim -= 1
  JArray.addObj(cells, dim, JArray.objectWithSize(8))
endwhile

JValue.solveStrSetter(cells, "[1][7]", JValue.objectWithPrototype("[\"bishop\", 0]"))
JValue.solveStrSetter(cells, "[2][6]", JValue.objectWithPrototype("[\"pawn\", 1]"))

int bishop = JValue.solveFlt(cells, "[1][7]")

Let's dump multidimensional array into a file:

JValue.writeToFile(mt, "array.json")
[
	[null, null, null, null, null, null, null, null],
	[null, null, null, null, null, null, null, ["bishop", 0]],
	[null, null, null, null, null, null, ["pawn", 1], null],
	[null, null, null, null, null, null, null, null],
	[null, null, null, null, null, null, null, null],
	[null, null, null, null, null, null, null, null],
	[null, null, null, null, null, null, null, null],
	[null, null, null, null, null, null, null, null]
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.