OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: louiscar on 28 May 2007, 07:17:46

Title: Problem with getting functions to work
Post 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



Title: Re: Problem with getting functions to work
Post by: h- on 28 May 2007, 09:47:38
Change this
Code: [Select]
_i = [9.33] call intto
Code: [Select]
_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..
Title: Re: Problem with getting functions to work
Post by: Mandoble on 28 May 2007, 09:47:47
try this:
Code: [Select]
int = compile (preprocessFileLineNumbers "int.sqf");
Title: Re: Problem with getting functions to work
Post by: Cheetah on 28 May 2007, 11:19:24
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).
Title: Re: Problem with getting functions to work
Post by: Mandoble on 28 May 2007, 15:08:42
LOL Cheetah, you broke the "magic" of that function  :good:
Title: Re: Problem with getting functions to work
Post by: louiscar on 28 May 2007, 17:42:49
Change this
Code: [Select]
_i = [9.33] call intto
Code: [Select]
_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
Title: Re: Problem with getting functions to work
Post by: louiscar on 28 May 2007, 17:45:32
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.
Title: Re: Problem with getting functions to work
Post by: louiscar on 28 May 2007, 17:58:24
Just tested and it works! Many many thanks guys !
Title: Re: Problem with getting functions to work
Post by: h- on 29 May 2007, 10:56:16
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.
Title: Re: Problem with getting functions to work
Post by: Arkon on 29 May 2007, 14:45:46

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
Title: Re: Problem with getting functions to work
Post by: Mandoble on 29 May 2007, 15:02:53
Well, the question is more related to "how to call a function" than to "how to write it"  :P
Title: Re: Problem with getting functions to work
Post by: louiscar on 29 May 2007, 22:15:56
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.
Title: Re: Problem with getting functions to work
Post by: h- on 29 May 2007, 22:32:50
Quote
Just wondering why this post was moved from the Scripting Advanced forum
Mandoble's right, executing a function is not exactly advanced stuff..