AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   trouble returning a float from a stock (https://forums.alliedmods.net/showthread.php?t=84245)

diamond-optic 01-22-2009 22:00

trouble returning a float from a stock
 
alright i feel really dumb about not understanding why this is happening..

but anyway im getting tag mismatch errors when i call the stock and also at the end of the stock (at the closing }), ingame it all seems to still work fine, but id really like to get rid of the error msgs..

this is in a function where its called:
Code:
new Float:hitOrigin[3] hitOrigin = get_hitplace_origin(victim,hitplace)

here's the stock:
Code:
stock get_hitplace_origin(id,hitplace) {     new Float:origin[3],Float:angles[3]     switch(hitplace)         {         case HIT_HEAD: hitplace = 19         case HIT_CHEST: hitplace = 11         case HIT_LEFTARM: hitplace = 15         case HIT_RIGHTARM: hitplace = 18         case HIT_STOMACH: hitplace = 9         case HIT_GENERIC: hitplace = 10         case HIT_LEFTLEG: hitplace = 3         case HIT_RIGHTLEG: hitplace = 6         }         engfunc(EngFunc_GetBonePosition,id,hitplace,origin,angles)                         return origin }

i do not get these errors if i dont use floats, but i rather just use the floats and save myself from having to convert them back and forth if at all possible

Exolent[jNr] 01-22-2009 22:47

Re: trouble returning a float from a stock
 
Why not just do this:
Code:
new Float:hitOrigin[3] get_hitplace_origin(victim,hitplace, hitOrigin)

Code:
stock get_hitplace_origin(id,hitplace,Float:origin[3]) {     new Float:angles[3]     switch(hitplace)         {         case HIT_HEAD: hitplace = 19         case HIT_CHEST: hitplace = 11         case HIT_LEFTARM: hitplace = 15         case HIT_RIGHTARM: hitplace = 18         case HIT_STOMACH: hitplace = 9         case HIT_GENERIC: hitplace = 10         case HIT_LEFTLEG: hitplace = 3         case HIT_RIGHTLEG: hitplace = 6         }         engfunc(EngFunc_GetBonePosition,id,hitplace,origin,angles) }

But, I will show you how to do it your way:
When returning values from a method, the data type must be declared:
Code:
// returning ints get_int() {     return 1; } // returning floats Float:get_float() {     return 1.0; } // returning booleans bool:get_bool() {     return true; } // IMPORTANT NOTE!: When returning an array, the receiving and sending arrayss must be the same cell size. // returning strings new mystring[20]; mystring = get_string(); //.. get_string() {     return "some stuff";     // or     new string[20];     // format string     return string; } // Invalid: new mystring[2]; mystring = get_string(); //.. get_string() {     new string[20];     //..     return string; } // Also invalid: new mystring[40]; mystring = get_string(); //.. get_string() {     new string[20];     //..     return string; } // and you can continue for other data types

diamond-optic 01-22-2009 23:19

Re: trouble returning a float from a stock
 
wow im embarrassed i even posted now.. the first method you posted works and is something i somehow never even thought of

thanks!

XxAvalanchexX 01-22-2009 23:29

Re: trouble returning a float from a stock
 
Exolent: Can you really return arrays if the dimensions are the same? I thought that you couldn't ever return them. But if so, that's pretty cool.

ConnorMcLeod 01-23-2009 00:44

Re: trouble returning a float from a stock
 
Yes we can :mrgreen:


All times are GMT -4. The time now is 01:49.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.