Bot Questions -

Ask for Help on Using the Language With Memory Hacking Software

Moderators: g3nuin3, SpeedWing, WhiteHat, mezzo

Postby Ereb » Mon Aug 11, 2008 12:11 am

Ok i solved the above problem, but now i have what will likely be marked down as another dumb question. I am working on adding functionality for casting spells, so i'm arranging the information into a struct then planning on passing it to a function to actually do the keypress'es and update a variable in the struct that contains the next time it can be cast. Unfortunately i'm lost on how to pass structs to functions i found this link for C style for this http://www.java2s.com/Code/C/Structure/Passstructintoafunction.htm however this syntax doesn't seem to be working in LSS. Here is my current test script
Code: Select all
struct Spell {
   long x;
   long y;
   float z;
};

void PrintSpell(struct Spell ThisSpell){
   PrintF("%d",ThisSpell.x);
   PrintF("%d",ThisSpell.y);
   PrintF("%f",ThisSpell.z);
}
void On_HK_5(){
struct Spell TestStruct;
   TestStruct.x = 10;
   TestStruct.y = 10;
   TestStruct.z = 3.1415927;
PrintSpell(TestStruct);
}

And the errors seem to state that the datatype isn't valid.
Code: Select all
ERROR: Invalid base size.  File: C:\Users\Farmer\Desktop\testscript.lss
ERROR: Line: 8 Invalid type for variable “ThisSpell”.  File: C:\Users\Farmer\Desktop\testscript.lss
ERROR: Line: 8 Unable to declare function.  File: C:\Users\Farmer\Desktop\testscript.lss

Sorry if I'm asking alot of questions but it seems that the C syntax doesn't work. Would i need to pass the struct by reference? And is this LSS specific, or does this span into C / C++

EDIT: Solved this one. The answer is to pass the struct by reference and get the values of the members using ->.
The Working Code:
Code: Select all
typedef struct {
   long x;
   long y;
   float z;
}Spell;

void PrintSpell(Spell * ThisSpell){
   PrintF("%d",ThisSpell->x);
   PrintF("%d",ThisSpell->y);
   PrintF("%f",ThisSpell->z);
}
void On_HK_5(){
Spell TestStruct;
   TestStruct.x = 10;
   TestStruct.y = 10;
   TestStruct.z = 3.1415927;
PrintSpell(&TestStruct);
}
Microsoft: "You've got questions. We've got dancing paperclips."
User avatar
Ereb
Hackleberry Fin
 
Posts: 20
Joined: Sat Jul 12, 2008 7:34 pm

Postby L. Spiro » Mon Aug 11, 2008 9:58 am

As you have found, I do not allow passing structures by value.
It is poor coding practice in all languages and creates slow code, as well as undesirable results in C++.

You need to pass a pointer to the structure instead. And this is not specific to L. Spiro Script; passing a pointer or reference is how it should always be done in C and C++.


L. Spiro
Our songs remind you of songs you’ve never heard.
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Previous

Return to Help

Who is online

Users browsing this forum: No registered users and 0 guests

cron