Notifications
Clear all
[Closed] Function in struct calls another function in same struct
May 01, 2011 2:31 pm
Hi all,
I’ve been wondering, is there a way for a function in a struct to call another function in the same struct without instancing the struct?
6 Replies
May 01, 2011 2:31 pm
struct exampleStruct
(
fn a = ( print "a" ),
fn b = ( exampleStruct.a() )
)
exampleStruct.b()
May 01, 2011 2:31 pm
some tricks with struct functions:
struct testStruct
(
a = 2, b = 3, ac, bc,
fn cc = ac()+bc(),
fn aa = a*a,
fn ab = aa()+b,
fn bb = aa()*b,
on create do
(
ac = aa
bc = ab
)
)
theStruct = testStruct()
theStruct.ab()
theStruct.cc()
theStruct.a = 4
theStruct.b = 5
theStruct.cc()
theStruct.ac = theStruct.bb
theStruct.cc()
May 01, 2011 2:31 pm
I don’t understand the on create part. Is aa a variable, or a function ? Where does it come from ?
1 Reply
aa is a function, ac is a variable… function cc defined before aa but after ac… so assigning aa to ac makes possible to run aa function from cc…