let's say i create a struct:
struct MyStruct{
int a;
String b;
DynamicSprite *c;
};
and some new variables for MyStruct:
MyStruct bla;
MyStruct blub;
MyStruct lala;
now i want to create a function where i am refering to these new variables like this:
function MyFunction(? var, int sprite){
var.a=var.a+1;
var.b="Hello!";
var.c=DynamicSprite.CreateFromExistingSprite(sprite);
}
instead of:
function MyFunction(int var1, String var2, DynamicSprite *var3 , int sprite){
var1=var1+1;
var2="Hello!";
var3=DynamicSprite.CreateFromExistingSprite(sprite);
}
is there a way to only refer to the first part of the new MyStruct variables instead of the whole variables?
struct MyStruct{
int a;
String b;
DynamicSprite *c;
import void MyFunction();
};
void MyStruct::MyFunction() {
this.a = 10;
this.b = "Test";
this.c.Delete();
}
This should do it for you.
And your last example would only altar a copy of the variables, not the variables themselves.
Edit: I forgot to include saying this, even though the question is answered, I'll add it for anyone else approaching this issue who stumbles upon this thread. You would call the struct function like so:
MyStruct instance; // creates the variable of the struct called instance
instance.MyFunction();
great, that's it! ;-D thank you!