Skip to content

user_type

BlidDev edited this page Jan 9, 2024 · 12 revisions

Overview:

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"
@WORKER

Fields are, as any variable in SGL, type-dynamic.


Default constructor/ ~* operator

usage example:

// template
set myobj ~*NAME

// specific use
set myobj ~*PERSON

Args:

  • 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.


make

usage example:

// template
make NAME ARGS...

// specific use
make WORKER ~*PERSON "fighting the king"

Args:

  • NAME: STR or CHAR
  • 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


setf

usage example:

// template
setf name field_name val

// specific use
setf ojb1 job "Running away from the king because hes winning"

Args:

  • name: STR or CHAR
  • field_name: STR or CHAR
  • 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


getf

usage example:

// template
getf name field_name

// specific use
set reason_of_death (getf ojb1 job)

Args:

  • name: STR or CHAR
  • field_name: STR or CHAR

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


setf_c

usage example:

// template
setf name field_names.. val

// specific use
setf_c obj1 pos x 5
// pretty much obj1.pos.x = 5

Args:

  • name: STR or CHAR
  • field_names: List of STR or CHAR
  • 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.


getf_c

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: STR or CHAR
  • field_names: List of STR or CHAR

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.

Clone this wiki locally