Notifications
Clear all

[Closed] rollout inside function of a struct cause struct member access requires instance

can someone explains why this isn’t working?


struct testbox
(
	b = box(),
	fn changeheight val =
	(
		b.height = val
	)
)

struct testInside 
(
	ui = undefined,
	c = testbox(),
	
	fn changeheight val = 
	(
		c.changeheight val
	),
	fn _ui =
	(
		 rollout unnamedRollout "Change Height" width:162 height:54
			 (
				 spinner spn1 "" pos:[56,19] width:50 height:16
				 on spn1 changed val do 
					 (
						 testInside.changeheight spn1.value -- this don't work
						 )
			)
			ui = unnamedRollout
			createDialog ui
	)
)

-- TEST 
c = testInside()
c._ui()
c.changeheight 30 -- but this works

4 Replies

Just from a quick glance, inside the rollout, you are accessing struct def itself, which cannot work since it needs a struct instance (which is what you do at the end where you first create an instance and call its function which works).

so there is no way other than creating an instance globally?

For example

struct testbox
(
	b = box(),
	fn changeheight val =
	(
		b.height = val
	)
)

struct testInside 
(
	ui = undefined,
	c = testbox(),
	
	fn changeheight val = 
	(
		c.changeheight val
	),

	fn _ui =
	(
		rollout unnamedRollout "Change Height" width:162 height:54
		(
			local testInside
			spinner spn1 "" pos:[56,19] width:50 height:16
			on spn1 changed val do 
			(
				testInside.changeheight spn1.value
			)
		)
		createDialog unnamedRollout
		unnamedRollout.testInside = this
	)
)

c = testInside()
c._ui()

there is a “this” keyword?
and wow didn’t know that you can’t do a reference the rollout to an object… Thanks!