Notifications
Clear all

[Closed] Using ByReference in structs possible?

If I have a struct. Can I call functions and use ByReference with local variables?
I鈥檓 getting System Exception errors.

First a function with ByReference

fn TheFunction &inVariable=
(
print inVariable –This creates a big error when called from the struct below.
)

I have a big struct:

struct BigObject=
(
localVariable=false,

fn LoadStuff=
(
TheFunction &localVariable –I鈥檓 calling by reference here
)
)

I noticed that it works if I write like this instead
newLocalVariable=localVariable
TheFunction &NewLocalVariable

However that would be extremely inconvinient to write for hundreds of variables鈥?/p>

/Andreas

7 Replies

Works out okay for me. Here is the quick example I made:


 fn myFunction &myVar = (
 	myVar = true
 )
 
 struct test (
 	var = false,
 	
 	fn init = (
 		myFunction &var
 	)
 )
 
 t = test()
 print t.var
 t.init()
 print t.var
 

Ok, thanks. I will look into my script in more detail when I get home. Hopefully I鈥檓 just doing something stupid.

/Andreas

I still can鈥檛 get it to work

This is the function that I鈥檓 calling with a reference variable. (the function is part of a bigger struct for handling load/save

fn Update Action variableName &Variable Default =
(
鈥揑niClass.Update #Save 鈥淟ock鈥?&Lock true
if Action==#Load then
(
tReturn=(Load variableName Default)
break()
return tReturn
)
else —#Save
(
var=Variable
break()
tReturn=(Save variableName var)

          return tReturn
      )        
  ),

This is how I call it. I call the function from inside a struct. Lock is a local variable.

TestIniClass.update iniAction 鈥淟ock鈥?&Lock false

If I instead write like this

newLock=Lock
TestIniClass.update iniAction 鈥淟ock鈥?&NewLock false

then it works, so the problem seem to be because of the Lock variable.

This is the error message:

鈥?Error occurred in update(); filename: C:\3dsmax8\Scripts\Polyspeed CODE\windowsclass23.ms; position: 4819
鈥? Frame:
鈥? Variable: <<error printing value>>
鈥? action: #save
鈥? default: false
鈥? variableName: 鈥淟ock鈥?br>
鈥? var: <<error printing value>>
鈥? tReturn: undefined
鈥? called in INIUpdate(); filename: C:\3dsmax8\Scripts\Polyspeed CODE\windowsclass23.ms; position: 71545
鈥? Frame:
鈥? newCategory: #no
鈥? iniAction: #save
system exception

If I use Global variables inside the struct, then the load/save works. Very strange. I think the problem comes from the fact that Lock is a local variable in the struct, but not in this very function. (it鈥檚 declared when I create the struct).

/Andreas

Just trying to get a grasp of the code you are trying to execute here. Would you say this example is relevant?


struct test (
	var = false,
	
	fn update &myVar = (
		myVar = true
	),
	
	fn init = (
		update &var
	)
)

t = test()
t.var
t.init()
t.var

If all of the functions for your example are in the same struct, I don鈥檛 see the need to call them by using the struct name first. Instead of TestIniClass.update <args> you could instead (if the function is inside the struct) just say update <args>.

Hiya.
No this is not the same

I have 2 different structs. One is for handling Ini objects, one is for handling interfaces.

The Interface Struct HAS the Ini Struct as an object. Functions in the Interface Struct calls the Ini Struct. When I call the ini class I send in several variables byreference that I hope to update.

For this example I skipped the ByReference, since it just didn鈥檛 work. But it would be nice to have it working in the future.

Right now I do something like this instead:
IniAction=#load –can also be #save
Variable=IniClass iniAction 鈥淰ariable鈥?Variable

This way I can both load and save the Variable with the exact same command.

Hey, can鈥檛 you guys do Descent 4? Descent was one of the best darn games ever made. I never had so much fun in multiplayer, EVER.

/Andreas

Ahh, I didn鈥檛 realize you were doing this with two seperate structs. I must have missed that.

The Descent 4 discussion pops up from time to time here, but sadly, I don鈥檛 think another version will ever be made. Besides, there doesn鈥檛 seem to be a market for that type of game anymore.

1 Reply
(@f97ao)
Joined: 11 months ago

Posts: 0

Yes, hmm it鈥檚 a shame. One clear problem was that it wasn鈥檛 very accessible. It was after all freaking hard to control the space ship, but when you DID learn to fly backwards in tunnels avoiding smart bombs, oh boy then it rocked. Perhaps if it was more packaged as a multi player game, it could work. It was never that much fun in single player actually.

/Andreas