Home   Help Search Login Register  

Author Topic: .sqf scripting problem!  (Read 2045 times)

0 Members and 1 Guest are viewing this topic.

Offline Nemesis6

  • Members
  • *
.sqf scripting problem!
« on: 10 Sep 2004, 22:18:08 »
Here's the script, or whatever you call it -

Quote
private
[
   "_soldier",
   "_ammo",
   "_shot",
   "_pos"
];
_soldier = _this select 0;
_ammo = "bullet7_6";
_shot = nearestObject [_soldier,_ammo];
_pos = getPos _shot;
_x = _pos select 0;
_y = _pos select 1;
_z = _pos select 2;
_maxPuffs = 2;
_i = 0;

if (_ammo != "bullet7_6") then {((_this select 0)) exec ""shockdust.sqs""; exit};

while {_i < _maxPuffs} do



{
drop ["cl_basic","","Billboard",1,8,[0,0,0],[(velocity _soldier select 0) / 2 + random 0.7 - random 0.7,(velocity _soldier select 1) / 2 + random 0.7 - random 0.7,0 + random 0.5],0,1,0.8,random 0.1,[0,3,4,5],[[0.85,0.85,0.85,0.05 + random 0.05],[0.85,0.85,0.85,0]],[0,1,0,1],0,0,"","",_shot];
_i = _i + 1
}

Now, I think it's pretty obvious what I'm trying to do, but in case it's not, it's a script/function for tank MGs. So, if the thing fired isn't an MG bullet, it needs to execute shockdust.sqs and quit.

Any help appriciated. Note that this is the latest attempt, so I may have overdone the shockdust thing.
« Last Edit: 10 Sep 2004, 22:49:22 by Nemesis6 »
I am actually flying into a star... this is incredible!

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:.sqf scripting problem!
« Reply #1 on: 10 Sep 2004, 23:06:22 »
Not that I'll be able to help .... but what's going wrong?   Any error messages?   Or is there just nothing happening at all?      
Plenty of reviewed ArmA missions for you to play

Offline Nemesis6

  • Members
  • *
Re:.sqf scripting problem!
« Reply #2 on: 10 Sep 2004, 23:31:05 »
Well, here's the thing - I can't get it to do what I want if the Ammo isn't equal to "bullet12_7", however, if it is equal to that, I can make it do whatever I want... it's like, if == is replaced by != , the line is simply bypassed.
« Last Edit: 10 Sep 2004, 23:33:29 by Nemesis6 »
I am actually flying into a star... this is incredible!

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:.sqf scripting problem!
« Reply #3 on: 11 Sep 2004, 00:21:40 »
12_7 or 7_6?    You have one inthe function and one in the post.
Plenty of reviewed ArmA missions for you to play

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:.sqf scripting problem!
« Reply #4 on: 11 Sep 2004, 07:25:56 »
Code: [Select]
{((_this select 0)) exec ""shockdust.sqs"";exit}This is what troubles me...
Should be
Code: [Select]
{(_this select 0) exec "shockdust.sqs";exit}But, doing this part right does not work either as exit does not work in .sqf...
So, what ever you do the function always runs through from top to bottom...

And this is probably why you have troubles....

Try something like
Code: [Select]
if (_ammo != "bullet7_6")
 then
    {
     _soldier exec "shockdust.sqs";
    }
   else
      {
   while {_i < _maxPuffs}
     do
      {
       drop ["cl_basic","","Billboard",1,8,[0,0,0],[(velocity _soldier select 0) / 2 + random 0.7 - random 0.7,(velocity _soldier select 1) / 2 + random 0.7 - random 0.7,0 + random 0.5],0,1,0.8,random 0.1,[0,3,4,5],[0.85,0.85,0.85,0.05 + random 0.05],[0.85,0.85,0.85,0],[0,1,0,1],0,0,"","",_shot];
       _i = _i + 1;
      };
   };
Remember that the forums software here automatically 'lines' up the code so the drop stuff is a bit screwed...

Syntax has no guarantees... :P

Oh, and when doing .sqf ALWAYS penta-check that the end-of-line ( which is the ; ) is after each separate sentence...
And closing brackets must always also have ; ...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Nemesis6

  • Members
  • *
Re:.sqf scripting problem!
« Reply #5 on: 11 Sep 2004, 14:07:25 »
Well, it did sound more reasonable... but it didn't work.
I am actually flying into a star... this is incredible!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:.sqf scripting problem!
« Reply #6 on: 11 Sep 2004, 14:14:48 »
How?
Describe what happens/does not/should happen... To the t... :P
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Nemesis6

  • Members
  • *
Re:.sqf scripting problem!
« Reply #7 on: 11 Sep 2004, 14:49:23 »
EDIT: Here's a picture of the error, copy and paste the link into your browser.

http://geocities.com/facehugger96/error.JPG

PS. It should look like this -

Quote
private
[
   "_soldier",
   "_ammo",
   "_shot",
   "_pos"
];
_soldier = _this select 0;
_ammo = "bullet7_6";
_shot = nearestObject [_soldier,_ammo];
_pos = getPos _shot;
_x = _pos select 0;
_y = _pos select 1;
_z = _pos select 2;
_maxPuffs = 2;
_i = 0;

if (_ammo != "bullet7_6")
then
    {
    _soldier exec "shockdust.sqs";
    }
  else
      {
   while {_i < _maxPuffs}
     do
     {
       drop ["cl_basic","","Billboard",1,8,[0,0,0],[(velocity _soldier select 0) / 2 + random 0.7 - random 0.7,(velocity _soldier select 1) / 2 + random 0.7 - random 0.7,0 + random 0.5],0,1,0.8,random 0.1,[0,3,4,5],[0.85,0.85,0.85,0.05 + random 0.05],[0.85,0.85,0.85,0],[0,1,0,1],0,0,"","",_shot];
       _i = _i + 1;
     };
« Last Edit: 11 Sep 2004, 15:01:57 by Nemesis6 »
I am actually flying into a star... this is incredible!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:.sqf scripting problem!
« Reply #8 on: 11 Sep 2004, 16:37:06 »
Quote
Here's a picture of the error
:(
Typical...
That's most likely the 'Generic error in expression'....

I always have these same problems when using if/then/else... :(

It seems that the else part does not like if there's too much stuff in there, so try turning the whole thing around:

Code: [Select]
if (_ammo == "bullet7_6")
then
    {
  while {_i < _maxPuffs}
    do
    {
      drop ["cl_basic","","Billboard",1,8,[0,0,0],[(velocity _soldier select 0) / 2 + random 0.7 - random 0.7,(velocity _soldier select 1) / 2 + random 0.7 - random 0.7,0 + random 0.5],0,1,0.8,random 0.1,[0,3,4,5],[0.85,0.85,0.85,0.05 + random 0.05],[0.85,0.85,0.85,0],[0,1,0,1],0,0,"","",_shot];
      _i = _i + 1;
    }
  else
      {
    _soldier exec "shockdust.sqs";
    };
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Nemesis6

  • Members
  • *
Re:.sqf scripting problem!
« Reply #9 on: 11 Sep 2004, 18:52:52 »
Still doesn't work... :-/


I suddenly feel an inexplicable urge to say "Engine limitations!"...

EDIT... D'OH! I made an error in the drop array - I forgot to encapsulate the color array.
« Last Edit: 11 Sep 2004, 19:05:21 by Nemesis6 »
I am actually flying into a star... this is incredible!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:.sqf scripting problem!
« Reply #10 on: 11 Sep 2004, 19:05:13 »
It's giving the same error??
Where/how do you execute this script??

This hardly is an engine limitation, I've used/seen used much much more complicated stuff with no probs...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:.sqf scripting problem!
« Reply #11 on: 11 Sep 2004, 19:09:27 »
Hey there !


Considering that in .sqf files "there's no such thing as time" (quote from snYpir's Tut', I suspect that the drop command, which defines many time parameters, is structurally incompatible with the format of functions.

Of course, I might be, and hope I am, wrong.

Good luck,

Igor

Offline Nemesis6

  • Members
  • *
Re:.sqf scripting problem!
« Reply #12 on: 11 Sep 2004, 19:09:52 »
This was partly my fault, I made a bug in the drop-section. Here's the correct version -

Quote
private
[
   "_soldier",
   "_ammo",
   "_shot",
   "_pos"
];
_soldier = _this select 0;
_ammo = "Bullet7_6";
_shot = nearestObject [_soldier,_ammo];
_pos = getPos _shot;
_x = _pos select 0;
_y = _pos select 1;
_z = _pos select 2;
_maxPuffs = 1;
_i = 0;

while {_i < _maxPuffs} do

{
drop ["cl_basic","","Billboard",1,8,[0,0,0],[(velocity _soldier select 0) / 2 + random 0.7 - random 0.7,(velocity _soldier select 1) / 2 + random 0.7 - random 0.7,0 + random 0.5],0,1,0.8,random 0.1,[0,3,4,5],[[[0.85,0.85,0.85,0.05 + random 0.05],[0.85,0.85,0.85,0]]],[0,1,0,1],0,0,"","",_shot];
_i = _i + 1
}

However, I did mess around with a working version which I couldn't get to work, either.

EDIT again... it seems that it was actually the forums that f'd up the array...?!
« Last Edit: 11 Sep 2004, 19:14:50 by Nemesis6 »
I am actually flying into a star... this is incredible!

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:.sqf scripting problem!
« Reply #13 on: 11 Sep 2004, 19:10:25 »
So drop works in functions ? Awesome !  :o ;D

Offline Nemesis6

  • Members
  • *
Re:.sqf scripting problem!
« Reply #14 on: 11 Sep 2004, 19:17:16 »
The drop-array does indeed work in functions. If it didn't, gun-barrel smoke would not be possible.
I am actually flying into a star... this is incredible!

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:.sqf scripting problem!
« Reply #15 on: 11 Sep 2004, 19:23:15 »
Roger this, I didn't know, thanks ! :)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:.sqf scripting problem!
« Reply #16 on: 11 Sep 2004, 20:43:45 »
Quote
it seems that it was actually the forums that f'd up the array...?!
I think I warned about this in some of my earlier posts.. ::)
About the auto-lining... :P

I actually was about to ask if you'd checked the drop[] stayed in the right shape... :P

So, it works or not?
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Nemesis6

  • Members
  • *
Re:.sqf scripting problem!
« Reply #17 on: 11 Sep 2004, 22:35:32 »
Nope, but I got some help with it elsewhere, and I finally got it to work -

Quote
private
[
   "_soldier",
   "_ammo",
   "_shot",
   "_pos",
   "_maxPuffs",
   "_i",
   "_x",
   "_y",
   "_z"
];
_soldier = _this select 0;
_ammo = _this select 4;
_shot = nearestObject [_soldier,_ammo];
_pos = getPos _shot;
_x = _pos select 0;
_y = _pos select 1;
_z = _pos select 2;
_maxPuffs = 2;
_i = 0;

if (_ammo == "Bullet7_6") then {
    while {_i < _maxPuffs} do {
        drop ["cl_basic","","Billboard",1,8,[0,0,0],[(velocity _soldier select 0) / 2 + random 0.7 - random 0.7,(velocity _soldier select 1) / 2 + random 0.7 - random 0.7,0 + random 0.5],0,1,0.8,random 0.1,[0,3,4,5],[[[0.85,0.85,0.85,0.05 + random 0.05],[0.85,0.85,0.85,0]]],[0,1,0,1],0,0,"","",_shot];
        _i = _i + 1;
    }
}
else {
    _this exec "shockdust.sqs";
};
« Last Edit: 11 Sep 2004, 22:35:55 by Nemesis6 »
I am actually flying into a star... this is incredible!

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:.sqf scripting problem!
« Reply #18 on: 12 Sep 2004, 07:40:19 »
;D ;D
Me talking about checking the syntaxes... ::)
It seems I forgot one } from there... :P

:beat:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.