Home   Help Search Login Register  

Author Topic: foreach (object _x) ?  (Read 2232 times)

0 Members and 3 Guests are viewing this topic.

Offline Tomb

  • Contributing Member
  • **
  • in2 Metal? Go 2 my sig
foreach (object _x) ?
« on: 05 Oct 2003, 20:58:03 »

 :D heya all.

It's been a while, but thats just because I'm struggling to get my editor_Mod done!  :P ;D

I have managed to add numerous new features into a variety of objects & buildings,
and now I need YOU to help me out on this particular one:

I need a specific effect for a certain object, and it has to be "global" so to speak.
Say, some player do "this" (whatever action), and then something happens to ALL objects with the
specific className "TMB_blahBla" :hmm: get it?!  :D :thumbsup:

I guess I need some looped check, fired by TWO objects:

      - the "switch" object and the "TMB_BlahBla" object.

So that if I (player) hit the switch, this & that happens to ALL "TMB_BlaBlah" objects. There!

Can you freaks push me in the right direction, hm? Post me some coding, baby!  :-*  ;) ;D

Later,

   Tombs


Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:foreach (object _x) ?
« Reply #1 on: 05 Oct 2003, 21:56:08 »
hey tomby :wave: long taam no c :P

i think u can do it by creatin array of all objects in game (ya know how dats is :P)

nd den use scriptin on da array like dat

"if (typeof _X == ""TMB_blahBla"") then {_X effect}" foreach array

sounds kool 2 u ? ;) ;D

tel me if it works :P

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Tomb

  • Contributing Member
  • **
  • in2 Metal? Go 2 my sig
Re:foreach (object _x) ?
« Reply #2 on: 08 Oct 2003, 23:25:03 »

sonnuvabisquit ¤#/%¤¤(  >:(  this crap is really buggin' me!


See, I have this "power switch" model, an' I wanna integrate it with my own streetLamp addon.

Thus :  when switch has anim.phase "on" ---> old Tomsters lamps will light up  :D ( ::) )


here's what I'm trying (this is a trigger example though, but you get the drift) :

switchLamps=[("(typeof _x) == ""tmb_lampWhite"") count _x")]; "(object _x) inflame True" forEach switchlamps

...which basically stinks (its a string right)!!!

an' I also tried:

 switchLamps=[("(typeof _x) == ""tmb_lampWhite"") count _x")]; switchlamps inflame True

  - but the gameEngine doesn't like arrays combined with the "inflame" command  :P >:(


P.S.   yes, my lamp is based on the fire object, and no - it doesn't light up the whole frikkin map,
like most other lamps (incl. the BIS ones).

anyho'  -  please help me out here, lads!  :-* :'( ;D







Unnamed

  • Guest
Re:foreach (object _x) ?
« Reply #3 on: 08 Oct 2003, 23:54:54 »
This is a wild stab in the dark, excuse the pun :) But if you have a global array of lamp objects called lamp1,Lamp2..e.t.c:

Code: [Select]
switchlamps=[Lamp1,Lamp2...e.t.c]
Then you would just need this:

Code: [Select]
{_x inflame True} ForEach switchlamps
Or if you have an array of object ID's from the map

Code: [Select]
SwitchLamps=[12345,12346,12347]
you would use:

Code: [Select]
{(Object _x) inflame True} ForEach switchlamps

Offline Tomb

  • Contributing Member
  • **
  • in2 Metal? Go 2 my sig
Re:foreach (object _x) ?
« Reply #4 on: 09 Oct 2003, 12:52:07 »

 neah doubt there, m8  :D thats what I'd do...      








...





...




...



...that is if my lamps had any ID# 's in the first place!  ::) ( ;D )

j/k - see, with addon-objects, there IS no ID value, and thus I can't use that spell
which brings me back to my MAIN problem:

 :o HOW the bell do I create a functional array (or whatever useful magic wand) for my Lamp Addon?!

===============

Lemme give you all an example here:

I create 10 of them TMB_lamp's and use them as part of, say a plain BASE.
Then I create my "Power Switch" object, and the issue is all about making it
possinble to turn on the light on ALL lamps INSTANTLY when player (or any AI moron)
use the switch (change animationPhase of power switch model).

And it is supposed to be a default script, running INSIDE the power switch Addon,
coz (as stated above) I wanna integrate those two addons, the lamp & the switch.

 8) That way, ppl can easily make their "attack_the_Base" missions without creating
triggers with (for some ppl) annoying and/or difficult editing issues.  :P :)


And I have the conditions up and running - no probs there.
But I just cant create that WORKING array of the lamps!!!  >:( :(

It is supposed to work via the use of the lamp_class_Name:  "TMB_LampWhite" ...only, HOW?  ???






           You tell me!  :-*




Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:foreach (object _x) ?
« Reply #5 on: 09 Oct 2003, 15:21:45 »
how is dat

Quote
switchLamps=[("(typeof _x) == ""tmb_lampWhite"") count _x")]; "(object _x) inflame True" forEach switchlamps

conected 2 dat

Quote
"if (typeof _X == ""TMB_blahBla"") then {_X effect}" foreach array

::)

ohh - u use _X in both of em :P  :o

or is it som thingy dat came into ur mind while drinkin beer dat is oder dan ma sugetion ? ::)  :-X

make global array 4 all da objects in da game (anyone present triger i think ;))

do empty objects count as ny1 ?  :-\

if dey r den all u need 2 do is

"if (typeof _X == ""tmb_lampWhite"") then {_X inflame true}" foreach arrayname

or if u mebe wanna put all ur lamps in array alone ? ;D

den u do

"if (typeof _X == ""tmb_lampWhite"") then {switchLamps=switchLamps+[_X]}" foreach arrayname

or u can put all ur lamps in array usin deir cpp

use eventhandler init and make it exec script like dat

? count switchLamps < 1 : switchLamps=[]

mebe

:P

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline Tomb

  • Contributing Member
  • **
  • in2 Metal? Go 2 my sig
Re:foreach (object _x) ?
« Reply #6 on: 09 Oct 2003, 21:31:11 »
I'll try this, LCD, panx  :-*

(tomorrow, though, as I'm stinkin' tired now.... an' my neighbor just invited me in for a beer)  ::)



 ;D


fingers crossed  :-X

oh, and remember:
NO triggers in the final code, as it is to become a SCRIPT, fired by the
eventHandlers class in the config of the addon.  :)
« Last Edit: 09 Oct 2003, 21:32:43 by Tomb »

Unnamed

  • Guest
Re:foreach (object _x) ?
« Reply #7 on: 10 Oct 2003, 01:08:51 »
Quote
I create 10 of them TMB_lamp's and use them as part of, say a plain BASE.

Then use my first example, if you create them then you can give them names.
This is a wild stab in the dark, excuse the pun :) But if you have a global array of lamp objects called lamp1,Lamp2..e.t.c:

Code: [Select]
switchlamps=[Lamp1,Lamp2...e.t.c]
Then you would just need this:

Code: [Select]
{_x inflame True} ForEach switchlamps

If you can give them names, you can stuff em in an array. How you create them, only you can say :)

P.S Sounds like your doing the same thing I intend to do with my Forward Observer addon, the addon creates and maintains a list of the Observer's the designer places in the mission. Eventually it will be linked with another addon for Mortars.

http://www.ofpec.com/yabbse/index.php?board=43;action=display;threadid=13099

The function RegisterObserver.sqf contained in the addon, has the basics priciples for creating your array. Without any scripting required from the mission designer.

One particular problem will be having a different sets of lights associated with different switches, this may require some scripting by the mission designer.
« Last Edit: 10 Oct 2003, 02:46:03 by Unnamed »

Offline Tomb

  • Contributing Member
  • **
  • in2 Metal? Go 2 my sig
Re:foreach (object _x) ?
« Reply #8 on: 10 Oct 2003, 15:27:32 »
 :D hey unnamed, and thanx for reppin' m8, much appreciated.  :-* really!

But I have to insist on this, m8, that I want to AVOID any kind of mission editing;
thats why I asked my Q here in the first place  :o :)

I wanna stuff ALL the spells into those two addons and run it from there,
using "class eventHandlers" {}; in the config. The objects have to work right from scratch,
without any array making etc. from the player/user.

 :D Just like if you buy a book: you can open & read it right away!
don't need to do anything but pay for it, and here ya don't even have to do that!

So I hope I made it clear as possible now!  :P ;D

my problem is to stuff this WORKING array into the addon, that is :
my problem is to get the game engine to accept unnamed objects,
objects with no ther ID than the global config class name: "TMB_LampWhite"  :o


there!


 :-\ sorry unnamed, I hope U get my drift  :) unless this .sqf stuff that U talk about can do what I'm after then I'll have to look elsewhere.

but thx anyway, m8, I'll give it a shot & see if it sticks!  ;)

====================

@ lcd :    its a new day now, I'll test yer stuff too tonite  :-*

Tombster
« Last Edit: 10 Oct 2003, 15:29:52 by Tomb »

Unnamed

  • Guest
Re:foreach (object _x) ?
« Reply #9 on: 10 Oct 2003, 20:40:14 »
Quote
unless this .sqf stuff that U talk about can do what I'm after then I'll have to look elsewhere.

I know it sounds crazy, but it might just do that. A bit like your book analogue, you have to read it ;)

Quote
So I hope I made it clear as possible now!

Almost, but I was quite chuffed I managed to "guess" correctly from your original post's :D Not sure why you need to worry about it's class name though, as it will only limit who can run use the addon's, for no apparent benefit?

Quote
I'll give it a shot & see if it sticks!

It may be worth a try, save you having to figure out stuff like how to avoid the error messages when you use the count command on an undefined array.

But if it does not stick, email the addons to me at:

unnamed@operationflashpoint.freeserve.co.uk

It wont take long for me knock up what your after.

Offline Tomb

  • Contributing Member
  • **
  • in2 Metal? Go 2 my sig
Re:foreach (object _x) ?
« Reply #10 on: 11 Oct 2003, 01:33:57 »
nice  :-* its always good with some friendly ppl around the 'hood.

Maybe its because I'm danish; I always get the feeling that no one understand sh*t of what I'm trying to do  ::) ;D but that prob. dates back to when ole Tigershark was steering the boat  :-X ;D

I'd have to isolate the addons, though, as the entire pack is a brand new editor_mod (upgrade).

I'll fiddle around w/ your suggestion this weekend, m8. And if it gets nasty I'll consider taking advantage of yer kind offer  :-*

later

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:foreach (object _x) ?
« Reply #11 on: 11 Oct 2003, 02:00:16 »
nd alwayz feel free 2 send em 2 me also :P - i think i did somin like dat w/ da EC boat :P ;)

LCD OUT
« Last Edit: 11 Oct 2003, 02:00:26 by LCD »
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

andersgrim

  • Guest
Re:foreach (object _x) ?
« Reply #12 on: 20 Oct 2003, 16:52:28 »
Mates, what about going the simple way.
I know looping scripts aint the healthiest thingy 'round, but only thing i can think of.



Let's say when the switch is activated, it triggers the command
StreetlampActivated = true



Then in the streetlamps config, use eventhandlers to trigger their looping script like;
class EventHandlers
{
init = "[_this] select 0 exec {\Addon\scripts\script.sqs};";
};




And then let script.sqs loop like;

_lamp = _this select 0
#start
@StreetlampActivated: goto "cont"
goto "start"
#cont
_lamp inflame true
goto "start"



But as for the global thing, i'd like to see that in a new patch.
Let's say     Global(classname)

So that
global(TMB_LampWhite) inflame true
would light up all the TMB_LampWhite

micropilot

  • Guest
Re:foreach (object _x) ?
« Reply #13 on: 28 Nov 2003, 15:42:57 »
As I'm at work I can't try tyis, but if you can group non-AI vehicles in the editor you could have the mission designer group the lights with the switch.  

This would solve 2 problems:

1) now you can define which lights belong to which switch

2) you now have an array that the switch can manipulate ( units group this )