OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: louiscar on 28 May 2007, 07:17:46
-
Hi, I would appreciate a pointer to what might be wrong with implementing my function.
I wrote and tested a script but when I try to convert it for use as a function I get an error. I then wrote a simple test script to see if I could narrow it down but get the same error. Can anyone tell me what I'm doing wrong.
Here's the simple test and what I'm doing.
In init.sqs I've declared the following:
int = preprocessFile "int.sqf"
The function int.sqf contains:
private ["_h"];
_h = (_this) - (_this mod 1);
_h
I call this from a script like this:
_i = [9.33] call int
hint format ["Here is your integer sir: %1",_i]
The error I get with this and my original function is:
error call : [9.33] |#| call int, Type string, expected code
From what I've read on functions or looking at other examples I am doing it as others appear to be doing it but I just can't get past this error or figure out where the so called 'string' instead of code is being detected.
Any ideas would be appreciated.
regards
L
-
Change this
_i = [9.33] call intto
_i = [9.33] call compile intArmA handles code and strings differently now, functions are strings so the string has to be compiled first even it has been preprocessed..
-
try this:
int = compile (preprocessFileLineNumbers "int.sqf");
-
Floor (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=f#floor) and Ceil (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=c#ceil).
-
LOL Cheetah, you broke the "magic" of that function :good:
-
Change this
_i = [9.33] call intto
_i = [9.33] call compile intArmA handles code and strings differently now, functions are strings so the string has to be compiled first even it has been preprocessed..
Ah now that makes sense of the error. Thanks for the pointer (also Mandoble), I'll go and give this a try.
L
-
Floor (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=f#floor) and Ceil (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=c#ceil).
LOL! ok do you know how long I looked to find an int function? >:(
Thanks for that it'll make my main function a bit more straight forward now.
-
Just tested and it works! Many many thanks guys !
-
Good that you got it working :good: , but now my brain hurts because you have made a 'triple post'.. :no:
If you have something to add to your post after a short period of time (we'd prefer that about 3 days should pass), edit your post instead of replying to yourself.
-
Hi,
Just wondering why this post was moved from the Scripting Advanced forum when it specifically states that writing Funtions are dealt with in the "Is My Question Advanced?" post?
Or am I missing summint here...
please advise.
regards
Arkon
-
Well, the question is more related to "how to call a function" than to "how to write it" :P
-
Good that you got it working :good: , but now my brain hurts because you have made a 'triple post'.. :no:
If you have something to add to your post after a short period of time (we'd prefer that about 3 days should pass), edit your post instead of replying to yourself.
Understood. Sorry I didn't realise this was bad.
-
Just wondering why this post was moved from the Scripting Advanced forum
Mandoble's right, executing a function is not exactly advanced stuff..