May 26, 2024, 23:20:27

Author Topic: How to compose the "FocusDevice" command?  (Read 6545 times)

Offline GeoModder

  • Chief Petty Officer
  • **
  • Posts: 279
  • Karma: 4
    • View Profile
    • http://
How to compose the "FocusDevice" command?
« on: May 28, 2011, 08:30:27 »
Whatever I try, I keek getting an from the mission editor over the FocusDevice command in this code:

Code: [Select]
MakeFullyKnown(M.PShip.0, #race_Raptor);
SelectShips(22,s.shiptype=#styp_ep2_Hunter);
ExecList(22,
s.this:tMoveTo(M.PShip.0, 2, 0);
s.this:tFireTo(M.Pship.0, 3);
s.this:tEnergyMode(1, 2);
GetDevices(M.PShip.0,11);
ExecList(11,
FocusDevice(s.device=261, #race_raptor, 1);
);
);

It generates the following error:

Quote
---------------------------
MISSION_EDITOR_DX9 SCRIPT ERROR
---------------------------
Bad function parameter passed.

File: universe\mod_missions\2_Gamma.mission
Line: 184

Rule: event RaptorRaid

Expression: focusDevice(S.device = 261, 10, 1)
Parameter 1: Not a device


Device 261 is the "eng_bFusEng" in tacticstypes, the main engines thus.
The ship which it refers to is the "#styp_IPblocker_Cruiser" in tacticstypes.ini, and it definitely has this particular engine in its device loadout. I do add two squadrons in the mission file, but I suppose that shouldn't cause the error.
Can somebody tell me how I need to compose the FocusDevice command so he recognizes the refered device? Or what I put wrong in the parameters?
Btw, the error pops up too when I put "#race_player" in the second parameter. Tried it just in case I misinterpreted the description in the mod doc.
« Last Edit: May 28, 2011, 08:32:33 by GeoModder »

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
Re: How to compose the "FocusDevice" command?
« Reply #1 on: May 28, 2011, 11:17:41 »
The error is within the "s.device=261" code. FocusDevice() expects an actual device object there, but you supply it with a comparison:
  • s.device is 1, if the currently selected object is a device (otherwise it's 0) - it is always 1 here, since the list only contains devices because of the GetDevices()-call
  • =261 tests this value for equality with 261, which is obviously never true (0!=261 and 1!=261)
Thus, the actual value of "s.device=261" is always 0 (false), no matter the actual device at hand.
In order to fix this, I'd also replace the GetDevices()-call with a SelectDevices(), so you only select the engine(s) you care about instead of every device on the ship:

Code: [Select]
   SelectDevices(11, M.PShip.0, s.devType = #eng_bFusEng);
   ExecList(11,
      FocusDevice(s.this, #race_raptor, 1);
   );

I'd also suggest to always try and use constants like #eng_bFusEng in favor of the actual values (261), cause if you read this piece of code a few weeks later, you may have forgot what device 261 actually is. Using the constant makes the intention of the code (selecting fusion engines) much clearer and also more robust, because the actual device number may be suspect to change in later versions... resulting in nasty and hard to find bugs in your scripts.

Offline GeoModder

  • Chief Petty Officer
  • **
  • Posts: 279
  • Karma: 4
    • View Profile
    • http://
Re: How to compose the "FocusDevice" command?
« Reply #2 on: May 28, 2011, 11:59:58 »
Thanks.
Infact, I prefer to use the actual device name as well. It's just that using the numeric code for it was one of the last straws I could think of.
So, the fault in my thinking was to assume that once a list was made of the devices of a given ship, it would pick the requested device from the list later on instead of reading that, yes, there's something in that list.

But by using the "s.this" statement, would it be possible to put multiple devices in it? Or should I create a device selection and a consequential execlist command as many times as I need the attacker to target specific devices? In short, I want the attacker to target 2 or even 3 devices at once.

Offline Arparso

  • Administrator
  • Lieutenant
  • *****
  • Posts: 558
  • Karma: 14
  • I can see you...
    • View Profile
    • http://arparso.de/nexus
Re: How to compose the "FocusDevice" command?
« Reply #3 on: May 28, 2011, 20:34:31 »
So, the fault in my thinking was to assume that once a list was made of the devices of a given ship, it would pick the requested device from the list later on instead of reading that, yes, there's something in that list.
Well, when you collect stuff in a list (like, all devices of a specific ship), then the game won't magically select the right object for you later on. The command(s) you put in an ExecList() will be executed once for each object of the list. If you only want them to be executed for specific objects, then you'll either need to make sure to only gather these desired objects in that list and nothing else... or you'll need to put some additional conditions inside your ExecList(), like for example:

Code: [Select]
ExecList(11,
    If(s.devType = #eng_bFusEng,
         DoSomething(),
         DoSomethingElse()
    );
);

Quote from: Geomodder
But by using the "s.this" statement, would it be possible to put multiple devices in it?
The content of s.this may change during the execution of ExecList() or similar commands, because ExecList() loops over all the items on the list and executes the embedded command(s) for each of them, one at a time. So s.this already refers to these multiple devices, just one at a time and not all at once.

Quote from: Geomodder
Or should I create a device selection and a consequential execlist command as many times as I need the attacker to target specific devices? In short, I want the attacker to target 2 or even 3 devices at once.
As far as I understand it, you'd just need to run the FocusDevice()-command once for each device, with the last parameter set to 1. You can do this in one ExecList(), if you previously selected exactly these 2 or 3 devices in one list. E.g.:

Code: [Select]
SelectDevices(11, M.PShip.0, s.devType = 74 | s.devType = 81 | s.devType = 99);
This'd select all the devices of these three different DEVICETYPEs on that one ship, which you could then focus fire on by using a single ExecList() like I wrote in my last post.