[SOLVED] FxDTSBrick::setVehicle() Only Work Sometimes

Author Topic: [SOLVED] FxDTSBrick::setVehicle() Only Work Sometimes  (Read 1504 times)

Say I have a brickVehicleSpawnData brick, %spawn, that I just planted. If I run %spawn.setVehicle(JeepVehicle), nothing spawns. However, if I spawn a tank, and then run %spawn.setVehicle(JeepVehicle), a jeep spawns. However, if I then run %spawn.setVehicle(TankVehicle), the jeep remains. But if I manually respawn the jeep and run %spawn.setVehicle(TankVehicle), a tank spawns. Then predictably, %spawn.setVehicle(JeepVehicle) does not do anything. If I run %spawn.respawnVehicle() (which does successfully respawn the vehicle) and then run %spawn.setVehicle(JeepVehicle), nothing happens. However, if I wrench the brick and just click send, and then run %spawn.setVehicle(JeepVehicle), the vehicle is changed to a jeep.

I've checked the trace(), and it just looks like FxDTSBrick::setVehicle() is the only function being called when I use events or a wrench to change the vehicle. There appears to be a GameConnection object passed as a second argument (err... third if you include the FxDTSBrick object itself). But I have included this as an argument and it doesn't make a difference
« Last Edit: December 28, 2017, 06:20:12 AM by Platypi »

Try using the ID of the vehicle. like TankVehicle.getID()

similar issue exists for the add item event, since sending the client the datablock name doesnt work (to update their client sided tool menu)

in general, be careful about passing datablock names straight into functions. the event system converts any datablocks into id’s when passing into the relevant function.

In the future as Conan explains just pass an ID instead of a name.

nameToID("datanamehere")
This is the same as datanamehere.getID(), I just think nameToID is better in my opinion

I have a feeling that getID is faster in the engine..

In the future as Conan explains just pass an ID instead of a name.

nameToID("datanamehere")
This is the same as datanamehere.getID(), I just think nameToID is better in my opinion

I have a feeling that getID is faster in the engine..
::getID is probably faster because it's just returning the object's ID, where nameToID probably has to lookup the object's name in a table.
However, ::getID will give errors if the object doesn't exist, making nameToID a little more friendly to use in situations where a name may come up for something that may not exist. Like loading a save for example.

In the future as Conan explains just pass an ID instead of a name.
It worked fine when I used the ID instead. Will keep this in mind. Marking thread as [SOLVED]. Thank you all!

::getID is probably faster because it's just returning the object's ID, where nameToID probably has to lookup the object's name in a table.
However, ::getID will give errors if the object doesn't exist, making nameToID a little more friendly to use in situations where a name may come up for something that may not exist. Like loading a save for example.

If your code has JeepVehicle.getId() it will still have to use the name lookup to figure out what JeepVehicle is in order to call the method. The only difference is that a member function call is slightly slower than a global function call.

Simple test:

function test()
{
   %a = getRealTime();

   for(%i = 0; %i < 10000000; %i++)
      %v = JeepVehicle.getId();

   %b = getRealTime();

   for(%i = 0; %i < 10000000; %i++)
      %v = nameToId(JeepVehicle);

   %c = getRealTime();

   talk(%b - %a);
   talk(%c - %b);
}


NameToId is a tiny bit faster, but the difference is so small that it doesn't matter.

NameToId is a tiny bit faster, but the difference is so small that it doesn't matter.
Well that's interesting. Might as well just use nameToID then. Avoids console errors and it's faster.