Notifications
Clear all

[Closed] tell me about: Struct

could you guys please tell me more about Struct ?

where and when is it good to use ?
why is it good ?

i was wonderig if you could also post some examples (with comments).

research01
research02
research03

thanks in advance

5 Replies
 JHN

Structs are useful in many ways. You can use them as some sort of namespace, you can bundle a lot of functions in a struct that only handle string operations. The struct can then be accessed instanced and static.

struct strOps
(
  fn addString str1 str2 = (str1 + str2)
  fn getString = ()
  --etc
)

strOps.addString "mxs" "rocks"

Structs can also be used to make tools with UI’s, I do this a lot.
declare some rollouts in the struct and also all functionality needed to build the UI etc.

And structs can be used to store bundled information

struct employer (name, age, node, light)
dude = employer("Dude", 32, $box01, $omni02)

print dude.age

The structs can be stored again to nodes etc.

So these are some ways to use structs, for me it’s great to bundle functionality in a struct, because it reduces the need for global variables, simply declare a struct global and all functionality comes with it.

-Johan

You can also mix and match. For most of my scripts with a lot of variables I store all of the functions and variables that need to be global into a single struct.

So if you have NodeData.mcr

I’ll have a struct:

struct NodeDataStruct (
fn dostuff(),
nodes, propertyinfo, globalVarThing

)

NodeInfoStruct (ID, Creator, Owner)

NodeDataVars = NodeDataStruct()

when it’s easily propertyized let’s say you have an array in Nodes which are composed of NodeInfoStructs then you can say stuff like:

For n in NodeDataVars.Nodes where n.Creator == “Gavin” collect n.ID

It’s nice and easy to read code. You can think of them as similar to Dictionairies in Python.

great help guys, thanks a lot.

can i use integers, arrays, floats as arguments into structs rather then strings ?

1 Reply
(@focomoso)
Joined: 10 months ago

Posts: 0

What happens when you try it?

(answer: no problem, right?)

Actually, the rollout clause is a struct example for us. You can define local variables in rollout, define functions etc. And u may do the same in a struct.