Home   Help Search Login Register  

Author Topic: Problem with getting functions to work  (Read 2224 times)

0 Members and 1 Guest are viewing this topic.

Offline louiscar

  • Members
  • *
  • I'm a llama!
Problem with getting functions to work
« 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



« Last Edit: 28 May 2007, 07:20:13 by louiscar »
VISTA - Doesn't trust you
http://badvista.fsf.org/

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Problem with getting functions to work
« Reply #1 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..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Problem with getting functions to work
« Reply #2 on: 28 May 2007, 09:47:47 »
try this:
Code: [Select]
int = compile (preprocessFileLineNumbers "int.sqf");

Offline Cheetah

  • Former Staff
  • ****
Re: Problem with getting functions to work
« Reply #3 on: 28 May 2007, 11:19:24 »
Floor and Ceil.
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Problem with getting functions to work
« Reply #4 on: 28 May 2007, 15:08:42 »
LOL Cheetah, you broke the "magic" of that function  :good:

Offline louiscar

  • Members
  • *
  • I'm a llama!
Re: Problem with getting functions to work
« Reply #5 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
VISTA - Doesn't trust you
http://badvista.fsf.org/

Offline louiscar

  • Members
  • *
  • I'm a llama!
Re: Problem with getting functions to work
« Reply #6 on: 28 May 2007, 17:45:32 »
Floor and 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.
VISTA - Doesn't trust you
http://badvista.fsf.org/

Offline louiscar

  • Members
  • *
  • I'm a llama!
Re: Problem with getting functions to work
« Reply #7 on: 28 May 2007, 17:58:24 »
Just tested and it works! Many many thanks guys !
VISTA - Doesn't trust you
http://badvista.fsf.org/

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Problem with getting functions to work
« Reply #8 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.
« Last Edit: 29 May 2007, 11:05:36 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Arkon

  • Members
  • *
Re: Problem with getting functions to work
« Reply #9 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

Offline Mandoble

  • Former Staff
  • ****
    • Grunt ONE and MandoMissile suite
Re: Problem with getting functions to work
« Reply #10 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

Offline louiscar

  • Members
  • *
  • I'm a llama!
Re: Problem with getting functions to work
« Reply #11 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.
VISTA - Doesn't trust you
http://badvista.fsf.org/

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Problem with getting functions to work
« Reply #12 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..
« Last Edit: 29 May 2007, 22:34:29 by h- »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.