How to return a variable from a function

Nick87

Member
I was wondering if anyone could write me a small example script of how to send and return a variable into a function. I keep trying but I'm doing something wrong. A small example of something like, send a variable add two to it return it and display it would help tremendously. Thank you.
 

st!ff

Member
Code:
function tstfunc(int x) 
{
	return ${Math.Calc[1+${x}]
}



function main()
{
	variable int i
	call tstfunc 10
	i:Set[${Return}]
	echo ${i}
}
 

Nick87

Member
Thanks that helped a lot. I'm still getting an odd return though. I'm trying to return a value for the price of an item in the market. It seems to only return a null value. Here's a piece of the code.

function price (number)

....

while ${i:Inc} <= ${OrdersCount}
echo ${Orders.Get[${k}].Price}
return ${Math.Calc[${Orders.Get[${k}].Price}]}

}

function main ()
}
call price ${number}
echo ${return}
}

I've tried a few wayt to return it, like saving it as a float and sending it back to another float but they always return null or 0.00000. If anyone could shine some light onto what I'm doing wrong I would be very greatful
 

Valerian

ISX Specialist
Thanks that helped a lot. I'm still getting an odd return though. I'm trying to return a value for the price of an item in the market. It seems to only return a null value. Here's a piece of the code.

function price (number)

....

while ${i:Inc} <= ${OrdersCount}
echo ${Orders.Get[${k}].Price}
return ${Math.Calc[${Orders.Get[${k}].Price}]}

}

function main ()
}
call price ${number}
echo ${return}
}

I've tried a few wayt to return it, like saving it as a float and sending it back to another float but they always return null or 0.00000. If anyone could shine some light onto what I'm doing wrong I would be very greatful
case-sensitivity.

echo ${Return}
 
Wtf?

simple script:
Code:
function main()
{
    variable float F	
    call DoSomething
    F:Set[${Return}]
    echo F = ${F}
}

function:float DoSomething()
{
   return 599999.62	
}
As result i have

F = 599999.625000
What is wrong with this code?

Looks like cumulative error.

return 10.6
return 100.6
return 1000.6
return 10000.6
return 100000.6
return 1000000.6


F = 10.600000
F = 100.599998
F = 1000.599976
F = 10000.599609
F = 100000.601563
F = 1000000.625000
 
Last edited:

pr517

Active Member
There is nothing wrong with the code. That data type just has a certain degree of precision to it (around seven digits.)
 
Code:
variable float F
Try this instead
Code:
variable float64 F
Already tryed, result the same. So if you want to process some market orders with price delta = 0.01 ISK u will have troubles. atm one solution - if you want calculate some prices - max, min, avg, etc, you should do that in main function. IMHO
 
Code:
echo F = ${F.Precision[2]}
Precision works as Round(), for example, if i have F == 100000.625, when i make ${F.Precision[2]} as result i have 100000.63, not 100000.62. Tryed Precision, Centi, result the same.
Maybe its a feature, not a bug, but when it works with function's result we have extra cent.
 
Last edited:

Amadeus

The Maestro
Staff member
Does the extra "isk cent" really matter? Seriously....are we really using isxeve to micromanage items that are THAT cheap?

Or are you all undercutting expensive items by a fraction of an isk? If so, stop it.



for example, if i have F == 100000.625, when i make ${F.Precision[2]} as result i have 100000.63, not 100000.62.
What you're wanting is a float member "Floor" (which would work similar to http://www.cplusplus.com/reference/clibrary/cmath/floor/) You'll need to request this feature from Lax at lavishsoft.com or on IRC. It should be VERY easy for him to implement it.

Once you have that feature, then you'd be able to do something like ${F.Floor.Precision[2]} ...and then it should give you what you're wanting.


(p.s. If Lax suggests the 'Int' member of the float datatype, just remind him that you need a FLOAT return value, not INTEGER. The reason I mention this is that ${F.Int} would do the same thing as the C++ floor() function, but it sets the return type as an integer...so, you'd lose your floating point.)
 
Top Bottom