View Full Version : Probability / IsNil problem?
Jakerod
Mar 11 2010, 01:11
I have a car (car) and a guy (man1). The car has a 50/50 chance of being there. I want it so that if the car isn't there then the man isn't there but if the car is then the man is.
I have tried the following in the condition of presence fields:
if (isnil "car") then {false};
if (isnil "car") then {false}; if !(isnil "car") then {true};
if (isnil "car") then {false}; if (!isnil "car") then {true};
The problem is that even when I set the car to 100% there the man never shows up no matter what. If the car is there, he isn't there. If the car isn't, then he isn't. I don't want to do the deletevehicle thing in a trigger because it seems that I have so many units being deleted at the start of the mission that some of them won't delete because there seems to be a backlog of deletions. I can use isnil to get it so that it will delete one guy when the other is there but I can't seem to make it where if one is there the other stays and if one isn't the other deletes.
Anyone have a solution?
Note: This problem is a simplified problem. This is really going to get used with a game logic instead of a car and have the game logic delete a lot of men. But I figured it was easier to write it out and test it this way. I can see the car, I can't see the game logic.
I can see a few problems with this - firstly if "car" is what the vehicle is named in the editor then it does not need to be embedded in quotation marks eg "car" should read just: car
Secondly, you should be checking isNull not isNil as car is an object. So the first part of the if statement should read like this
If (isNull car) then...
The next problem is what variable does the state true and false relate to. You need to have something like _carVar = true or _carVar = false in the second part of the statement or something like
If !(isNull car) then {man1 setPos getPos car};
Jakerod
Mar 11 2010, 01:45
I can see a few problems with this - firstly if "car" is what the vehicle is named in the editor then it does not need to be embedded in quotation marks eg "car" should read just: car
Secondly, you should be checking isNull not isNil as car is an object. So the first part of the if statement should read like this
If (isNull car) then...
The next problem is what variable does the state true and false relate to. You need to have something like _carVar = true or _carVar = false in the second part of the statement or something like
If !(isNull car) then {man1 setPos getPos car};
I was under the impression that anything in the condition of presence field automatically has a variable. Since by default it just says true. I didn't write I had those written in the condition of presence field. I just edited to reflect that now though.
So far I have tried:
if (isnil car) then {false};
if (isnil "car") then {false};
if (isnil car) then {false}; if !(isnil car) then {true};
if (isnil "car") then {false}; if (!isnil "car") then {true};
if (isnil "car") then {false}; if !(isnil "car") then {true};
if (isnil car) then {false}; if (!isnil car) then {true};
if (isnull "car") then {false}; (error)
if (isnull car) then {false};
if (isnull car) then {false}; if !(isnull car) then {true};
if (isnull car) then {false}; if (!isnull car) then {true};
Ah OK - I missed that part so maybe try:
If !(isNull car) then {true} else {false};
PS: not sure whether you can use presence fields in this way.
If it doesn't work then place the guy next to the car in the editor and in the init.sqf put:
if (isServer) then
{
if (isNull car) then {deleteVehicle man1};
};
Jakerod
Mar 11 2010, 01:54
Ah OK - I missed that part so maybe try:
If !(isNull car) then {true} else {false};
PS: not sure whether you can use presence fields in this way.
If it doesn't work then place the guy next to the car in the editor and in the init.sqf put:
if (isServer) then
{
if (isNull car) then {deleteVehicle man};
};
Also didn't work. Also tried these but they didn't work.
If !(isNull car) then {true} else {false};
If (isNull car) then {false} else {true};
If (isNil car) then {false} else {true};
If (isNil "car") then {false} else {true};
Well the condition of presence field at least works. Putting "cadetmode" in it makes him show up. That init.sqf thing is my last resort. I really want to be able to make it so that I can just copy and paste the one line of code into multiple units. I also don't want them to be deleted because it has been causing problems. I just want them to not be there.
One final thing before I shut up can you reverse the init.sqf thing ie. create the units in or via the init.sqf rather than deleting the editor place units if the gamelogic is present?
eg
if (isServer) then
{
if !(isNull car) then
{
"USMC_Soldier_Medic" createUnit etc...
};
};
I'll watch this as I'm interested to see if there is an easier way to do this.
EDIT: You'll need to create a group first if these dynamically created units will belong to a new group
Jakerod
Mar 11 2010, 02:10
One final thing before I shut up can you reverse the init.sqf thing ie. create the units in or via the int.sqf rather than deleting the editor place units if the gamelogic is present?
eg
if (isServer) then
{
if !(isNull car) then
{
"USMC_Soldier_Medic" createUnit etc...
};
};
I'll watch this as I'm interested to see if there is an easier way to do this.
EDIT: You'll need to create a group first if these dynamically created units will belong to a new group
The problem is that I will have to do that for several hundred units. Not to mention give all of them waypoints and then sync those waypoints to the triggers. And since I am not that good at writing out the code I don't think that will work out for me very well. I'm sure that it would probably work for one or a few units but doing it for as many as I would have to would take me forever.
galzohar
Mar 12 2010, 01:29
Why do If (isNil "car") then {false} else {true}; rather than just writing the actual condition isNil "car"? I wouldn't think the game actually runs the code in the condition field? If you want to actually run code there (which is not the case you're describing) then you need to have call {...} in there and have it return true or false in the end.
Deleting a lot of units is also not a big deal, you can always execute some kind of deletion script through all of them, and then you can even have the script wait until some other, more complicated calculations are done before deciding if to delete that unit or not. If you wanted to just do it in the condition field using call you'd have to re-calculate it for each unit as any calculation you result you would place in a global variable is not guaranteed to happen before the condition is checked.
])rStrangelove
Mar 12 2010, 09:59
Description:
Tests whether the variable is null. The function returns true if the variable is null and false if it's not.
Example:
if (isNil("_pokus")) then {_pokus=0;}
isNil only checks if a VARIABLE is null.
isNull checks if an OBJECT is null.
Your car is an object, isnt it?
galzohar
Mar 12 2010, 12:32
isNil checks if the variable is defined. If the car does not exist then the variable of its name is not defined, and therefore using isNull on it will not work. isNull checks if a defined variable is pointing to a null object.
Mr.Peanut
Mar 12 2010, 12:42
Try using str this(for the car) in your condition. It should have a testable string value whether the car exists or not. You also have the problem of whether the init for the car or the man runs first. Can't think offhand of how to solve this existential dilemma. If they are both civilian and you placed each car before each man you should be okay. Maybe. Otherwise you are most likely sol with this approach.
galzohar
Mar 12 2010, 13:55
Condition of presence is probably checked before any inits are run, as units that don't exit will not run their init lines at all. Vehicle variable names are defined before the condition is checked, though, so checking if it is defined or not (by using isNil "varName") should work to tell you if the vehicle exists or not.
galzohar
Mar 12 2010, 18:59
Some testing shows that the variable name is only defined when the unit is created. That is, if you place unitX first and then place unitY with condition of presence !isNil "unitX" then it'll work, but if you place unitY first then unitX will always be nil and !isNil "unitX" will always be true. Also certain sides will always run before other sides regardless of placement order (for example, bluefor will always run before empty, so you cannot place bluefor units based on presence of empty units). Therefore it's probably best to use deletion scripts rather than rely on the order in which units are placed in the editor.
I think the order is straight from the mission.sqm. You can also change the order in it by opening it with a text editor. Obviously, its not very good method, but nice thing to know as a last resort so that you dont need to redo half the mission. :)
Jakerod
Mar 12 2010, 22:03
Thanks guys. I think Galz is right. I'll just have to be careful about what order I place things in and if all else fails I can try the mission.sqm part of it. And if that fails then I guess the delete trick will have to work.
galzohar
Mar 12 2010, 22:55
The order does not matter if the units are not on the same side, as sides have a pre-defined order (I'd assume you can see it in mission.sqm), so this method will not work at all if you want, for example, to base the presence of bluefor units on the presence of game logics or empty units.
Scripts run after all editor items and init lines are run, so you should be fine doing the deletion in a script. You shouldn't have any problems with that, at least if you delete the stuff only on the server and delete crew before deleting the vehicle/static weapon.
Yep, either spawn units or place everything and run delete at init.sqf, so much less work and easier to modify later.
Demonized
Dec 12 2010, 21:14
Edit, removed.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.