Passing initialization value to nested struct as a reference?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

 
Thread Tools Display Modes
  06 June 2018
Passing initialization value to nested struct as a reference?

Im having some trouble using nested structs because I cant access values from the parent struct, and because the values change at runtime I cant just pass the values to the struct on create, because they would become out of date later.


global Temp
(
   struct MainStruct
   (
      MainStructValue = 1,
      NestedStruct =
      (
         struct NestedStruct (
            referenceValue,
            fn TestValue = (print referenceValue)
         )
      ) referenceValue:&MainStructValue,
      
      fn ModifyValue = ( MainStructValue += 1),
      on create do ()
   )
   Temp = MainStruct()
   Temp.ModifyValue()
   Temp.NestedStruct.TestValue()
)


So i had this idea to pass the values to the nested struct by reference. To my surprise it actually compiles, but the problem is its not really working as i would want it
print referenceValue
returns a "Struct member:MainStructValue" which is of type ValueRef. the documentation for ValueRef is pretty much nothing, so i was wondering if anyone has any ideas how I could actually cast this to a usable type? Ive also looked in to the dereferencing documentation with * but i cant seem to get it to work.. it just keeps returning "Struct member:MainStructValue"
 
  06 June 2018
Works with array. Not sure if it is possible for other value types

global Temp
(
    local xyz
   struct MainStruct
   (
      MainStructValue = #(),
      NestedStruct =
      (
         struct NestedStruct (
            referenceValue,
            fn TestValue = (format "%\n" (*referenceValue))
         )
      ) referenceValue:&xyz,

      fn ModifyValue = ( append MainStructValue 1),
      on create do xyz = MainStructValue
   )
   
   Temp = MainStruct()
   Temp.ModifyValue()   
   Temp.NestedStruct.TestValue()
   Temp.ModifyValue()   
   Temp.NestedStruct.TestValue()
   Temp.ModifyValue()   
   Temp.NestedStruct.TestValue()

)

Quote: #(1)
#(1, 1)
#(1, 1, 1)
 
  06 June 2018
Indeed, using an array as a wrapper for the actual values seems to work. Makes the implementation a bit more verbose than I would like but i guess its better than nothing
 
  06 June 2018
Any reason not to do it this way?

global Temp
(
    struct NestedStructDef
    (
        owner,
        fn TestValue = print owner.MainStructValue
    )
    struct MainStruct
    (
        MainStructValue = 1,
        NestedStruct = NestedStructDef owner:this,

        fn ModifyValue = MainStructValue += 1,
        on create do ()
    )

    Temp = MainStruct()
    Temp.ModifyValue()
    Temp.NestedStruct.TestValue()
)
__________________
Scripts :: linkedin
 
  06 June 2018
If you want to keep your 'nested struct' structure, you can use:
__________________
Andrés FC.
P3D_PathScripts

Last edited by aaandres : 07 July 2018 at 11:34 AM.
 
  06 June 2018
Awesome, this is exactly what I was looking for! Im assuming it works for private members too?
 
  06 June 2018
Originally Posted by Saippua: Awesome, this is exactly what I was looking for! Im assuming it works for private members too?
Nope. It's still considered as external accessing to private values. :(
__________________
Andrés FC.
P3D_PathScripts
 
  06 June 2018
...................
__________________
Andrés FC.
P3D_PathScripts

Last edited by aaandres : 07 July 2018 at 11:35 AM.
 
  06 June 2018
....................
__________________
Andrés FC.
P3D_PathScripts

Last edited by aaandres : 07 July 2018 at 11:35 AM.
 
  06 June 2018
............................
__________________
Andrés FC.
P3D_PathScripts

Last edited by aaandres : 07 July 2018 at 11:35 AM.
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright ©2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 09:57 AM.


Powered by vBulletin
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.