Notifications
Clear all

[Closed] Struct Woes

what ever i do i keep hitting a wall.

The code below, i’m trying to create an instance of a struct, but when running the code below using a when change handler i keep getting “Struct member access requires instance”

Any ideas anyone?






struct testStruct (
   node=undefined,
   instanceVar,


   fn testFn = (
      print "True"
   ),


   fn run = (
      when transform node Changes id:#offset node do(instanceVar.testFn())
   )
)
inst             = testStruct()
inst.instanceVar    = inst
inst.node          = selection[1]
inst.run()


Thanks!

2 Replies

… thats annoying…

i had the instanceVar in the wrong place.


struct testStruct (
   node=undefined,


   fn testFn = (
      print "True"
   ),


   fn run = (
      when transform node Changes id:#offset node do(testStruct.testFn())
   ),


   instanceVar = undefined
)
inst             = testStruct()
inst.instanceVar    = inst
inst.node          = selection[1]
inst.run()

Struct self reference was explained several times here on forum.


deleteAllChangeHandlers id:#offset

(local owner
struct testStruct (
   node = undefined,
   instanceVar,


   fn testFn = (
      print "True True"
   ),


   fn run = (
      when transform node Changes id:#offset node do (owner.testFn())
   ),
   
   on create do owner = instanceVar = this
)
)
inst             = testStruct()
inst.node          = selection[1]
inst.run()