Jump to content
Pokemoncrusher 1

Why does this script with no class defined work, but one with it does?

Recommended Posts

P1 addAction ["execute", "{deleteVehicle _x} forEach nearestObjects [player, [], 20]"]

This script above works and deletes all objects within 20meters, however, since the [ ] after position(player in this case) is empty, this sets the class to all, meaning it returns a list of every object in 20meters, I only want it to target cars. 

However, whenever I try to add a class to it, it tells me it is missing a ] 

P1 addAction ["Exec the file", "{deleteVehicle _x} forEach nearestObjects [player, ["Cars"], 20]"]

xeuWRUe.png

 

the only change is the addition of a class, I don't truly know why this is happening. this code matches the exact syntax on BIS website for nearestObjects, unless my add action or delete vehicle syntax is incorrect. I am stumped. If anyone can help me figure out the problem I would be very grateful! 

Share this post


Link to post
Share on other sites

1 - "cars" is not a workable class. "car" is... as well as "landVehicle" or "tank"

2 - you have a copy/paste bug (an extra invisible character between " and cars")

 

 

  • Like 1

Share this post


Link to post
Share on other sites

3- using string within a string wrong, should be:  "{deleteVehicle _x} forEach nearestObjects [player, ['Car'], 20]"

  • Like 1

Share this post


Link to post
Share on other sites
6 minutes ago, pierremgi said:

1 - "cars" is not a workable class. "car" is... as well as "landVehicle" or "tank"

2 - you have a copy/paste bug (an extra invisible character between " and cars")

 

 

I am mistaken on the class though so thank you for pointing it out, I did try other classes before and again now but the same issues persist,

As far as a copy-paste bug, I just retyped the entire code from scratch,as well as the class but still get the same issue.

Share this post


Link to post
Share on other sites
1 minute ago, h - said:

3- using string within a string wrong, should be:  "{deleteVehicle _x} forEach nearestObjects [player, ['Car'], 20]"

the issue here was wrong quotation marks? ' vs " I looked at many sources and they all used the double variant, when you use a string within a string I need to use the single quotation variant?

Thank you so much, I am very new and these small nuances drive me crazy for hours. 

Share this post


Link to post
Share on other sites
3 minutes ago, Pokemoncrusher 1 said:

when you use a string within a string I need to use the single quotation variant?

You may have understood wrong, ' is often referred as double quote because it "translates" to the game as "", so single ' is the same as "".
As in "['foo']" is the same as "[""foo""]".

To confuse more, it also works the other way around, if your string starts and ends with ' you can use " in it:
'["foo"]'

Also in case of addaction you could wrap your code as code instead of a string, then the string stuff is not a problem at all:
{{deleteVehicle _x} forEach nearestObjects [player, ["Car"], 20]}

  • Like 2

Share this post


Link to post
Share on other sites
1 minute ago, h - said:

You may have understood wrong, ' is often referred as double quote because it "translates" to the game as "", so single ' is the same as "".
As in "['foo']" is the same as "[""foo""]".

To confuse more, it also works the other way around, if your string starts and ends with ' you can use " in it:
'["foo"]'

Also in case of addaction you could wrap your code as code instead of a string, then the string stuff is not a problem at all:
{{deleteVehicle _x} forEach nearestObjects [player, ["Car"], 20]}

Ok, I understand now. Thank you so much for your help! 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×