Repository navigation
user_type
UserType is Niv's equivilant of a struct; it basically acts as a typedef struct would in C. You can define a new UserType in your program like so:
@NAME
field_name : default_value
...
@NAME
// so an example UserType will look like something like this
@PERSON
name : "Cred"
age : 17
@PERSON
// fields are often just regular data type but can also
// contain other UserTypes:
@WORKER
person : ~*PERSON // the ~* operator will be explained later
job : "Protecting the king"
@WORKERFields are, as any variable in SGL, type-dynamic.
usage example:
// template
set myobj ~*NAME
// specific use
set myobj ~*PERSONArgs:
-
NAME: A string literal containing a registered UserType name, for example~*PERSON
Desc:
Takes a name of a UserType type and returns an object of that given type containing its default values defined in the UserType decleration (see above).
Return value: A UserType with default values.
usage example:
// template
make NAME ARGS...
// specific use
make WORKER ~*PERSON "fighting the king"Args:
-
NAME:STRorCHAR -
ARGS...: List of arguments of any value
Desc:
Creates and returns a new UserType with custom values, given in order to the command (see specific example).
Return value: The constructed UserType object.
For more complex examples check user_type.nst
usage example:
// template
setf name field_name val
// specific use
setf ojb1 job "Running away from the king because hes winning"Args:
-
name:STRorCHAR -
field_name:STRorCHAR -
val: Any value
Desc:
Sets the field field_name of UserType name to val.
Return value: The value of val.
For more complex examples check user_type.nst
usage example:
// template
getf name field_name
// specific use
set reason_of_death (getf ojb1 job)Args:
-
name:STRorCHAR -
field_name:STRorCHAR
Desc:
Retrieves the value of UserType object name's field called field_name.
Return value: The value of the field.
For more complex examples check user_type.nst
usage example:
// template
setf name field_names.. val
// specific use
setf_c obj1 pos x 5
// pretty much obj1.pos.x = 5Args:
-
name:STRorCHAR -
field_names: List ofSTRorCHAR -
val: Any value
Desc:
Setf chained. When an object has a field of its own (say player.pos) and you need to set one of the fileds filed then you'd use this command.
Return value: The value of val.
usage example:
// template
setf name field_names..
// specific use
set f (setf_c obj1 pos x 5)
// pretty much f = obj1.pos.x Args:
-
name:STRorCHAR -
field_names: List ofSTRorCHAR
Desc:
Setf chained. When an object has a field of its own (say player.pos) and you need to get one of the fileds filed then you'd use this command.
Return value: The value of the nested field.