Notifications
Clear all

[Closed] Can't figure out how to access member in a structure

I’m trying to use structure to mimic object oriented programming but i’m facing a problem. Here is my code skeleton :

struct myUIStruct
(
	CONST_UI_WIDTH = 400,
	CONST_UI_HEIGHT = 300,
	
	theRollout,
	
	on create do 
	(
		rollout theRollout "Test" width:CONST_UI_WIDTH height:CONST_UI_HEIGHT
		(
		)
	),
	
	fn createForm =
	(
		createDialog theRollout
	)
)
myUIStruct_Instance = myUIStruct()
myUIStruct_Instance.createForm()

I’ve got this error message :

Runtime error: Struct member access requires instance: CONST_UI_WIDTH

I’ve tried with “this” same mesage.
I’ve tried with “myUIStruct.CONST_UI_WIDTH” and it can’t found CONST_UI_WIDTH in the struct :

Unknown property: "CONST_UI_WIDTH" in #Struct:myUIStruct(

If someone can explain me what i’m doing wrong.

Thanks

5 Replies

in your specific case just set width and height of a dialog with createDialog (not with its rollout definition)

As simple as that, thanks DenisT.

Do you know the true reason why it’s not working in a rollout definition ?

in two words: because at the moment of on create handler (that makes rollout) definition the structure is not created yet.

1 Reply
(@tonydugard)
Joined: 11 months ago

Posts: 0

that’s weird because if i’m doing this :

struct myUIStruct
(
	CONST_UI_WIDTH = 400,
	CONST_UI_HEIGHT = 300,
	CONST_BUTTON_TITLE = "myButton",
	
	theRollout,
	
	on create do 
	(),
	
	fn init =
	(
		rollout theRollout "Test" width:CONST_UI_WIDTH height:CONST_UI_HEIGHT
		(	
			button myButton CONST_BUTTON_TITLE 
		)
	)
)
myUIStruct_Instance = myUIStruct()
myUIStruct_Instance.init()

i’ve got the same error and the structure is created and then i’ve build the rollout (that was my first attempt). What do you thing about that ?

PS : thanks for you’re other post it’ll be usefull

check this post http://forums.cgsociety.org/showpost.php?p=6640830&postcount=7
it might be helpful for you or interesting at least