Jump to content
Mirek

[Solved] Random explosion at one of the markers.

Recommended Posts

Hi,

I am trying to create an explosion. The explosion should occur at one of five places defined by markers brk_1 to brk_5.

Iam using command:

bomb1 = "Bo_GBU12_LGB" createVehicle  (getmarkerpos "brk_2");

Vich itself works well.

 

Iam triing to randomize with:

posbomb=["brk_1","brk_2","brk_3","brk_4","brk_5"]; 
bombpos = posbomb select (floor random 5);  
  
hint format ["%1",bombpos];

Wich also works as any time i fire the related trigger i get hint with different "brk".

 

But when i try to put it togeter:

posbomb=["brk_1","brk_2","brk_3","brk_4","brk_5"]; 
bombpos = posbomb select (floor random 5);  
bomb1 = "Bo_GBU12_LGB" createVehicle getPos "bombpos"; 

it doesnt work.

 

I tried different things like:

Spoiler

p_1 = (getMarkerPos "brk_1"); 
p_2 = (getMarkerPos "brk_2"); 
p_3 = (getMarkerPos "brk_3"); 
p_4 = (getMarkerPos "brk_4"); 
p_5 = (getMarkerPos "brk_5"); 

SV=["p_1","p_2","p_3","p_4","p_5"];

PV = SV select (floor random 5);

B_1 = "Bo_GBU12_LGB" createVehicle  PV;

 

or

Spoiler

PosBomb=["brk_1","brk_2","brk_3","brk_4","brk_5"];
bomb = PosBomb call BIS_fnc_selectRandom;
bomb1 = "Bo_GBU12_LGB" createVehicle  (getmarkerpos "bomb");

 

or

Spoiler

bomb = ["brk_1","brk_2","brk_3","brk_4","brk_5"] call BIS_fnc_selectRandom; 
bomb1 = "Bo_GBU12_LGB" createVehicle  (getMarkerPos "bomb");

 

I tried differnt ways to set the possition

Spoiler

bomb1 = "Bo_GBU12_LGB" createVehicle  (getMarkerPos "bomb");
bomb1 = "Bo_GBU12_LGB" createVehicle  getMarkerPos "bomb";
bomb1 = "Bo_GBU12_LGB" createVehicle  getMarkerPos bomb;
bomb1 = "Bo_GBU12_LGB" createVehicle  (getPos "bomb");
bomb1 = "Bo_GBU12_LGB" createVehicle  getPos "bomb";
bomb1 = "Bo_GBU12_LGB" createVehicle  getPos bomb;

 

Iam out of ideas.

 

Share this post


Link to post
Share on other sites

@Mirek,

bomb = "Bo_GBU12_LGB" createVehicle (getMarkerPos (selectRandom ["brk_1", "brk_2", "brk_3", "brk_4", "brk_5"]));

 

  • Thanks 1

Share this post


Link to post
Share on other sites
13 minutes ago, Schatten said:

@Mirek,


bomb = "Bo_GBU12_LGB" createVehicle (getMarkerPos (selectRandom ["brk_1", "brk_2", "brk_3", "brk_4", "brk_5"]));

 

Could never gues it would be so easy. Thank you man, You saved me.

 

Share this post


Link to post
Share on other sites

Just to guide you, you can use select floor random (or even select random), or bis_fnc_selectRandom,

  or definitely best  selectRandom

but you must make the difference between:

- a marker "brk_1" which always refers to a "string", it's position is given by getMarkerPos,

- a class (typeOf) object like "Bo_GBU12_LGB" which is also a string, useful in some commands like createVehicle,

- a vehicle/object for which the variable (local: _bomb, global bomb) is never a string. It's position is given by getpos

- but a variable can refer to a marker. When you write:

bomb = ["brk_1","brk_2","brk_3","brk_4","brk_5"] call BIS_fnc_selectRandom;

bomb1 = "Bo_GBU12_LGB" createVehicle (getMarkerPos "bomb");  //// FALSE

 

bomb is already a variable returning a marker string, not a marker itself. So getMarkerpos bomb will work.

 

Share this post


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

Just to guide you, you can use select floor random (or even select random), or bis_fnc_selectRandom,

  or definitely best  selectRandom

but you must make the difference between:

- a marker "brk_1" which always refers to a "string", it's position is given by getMarkerPos,

- a class (typeOf) object like "Bo_GBU12_LGB" which is also a string, useful in some commands like createVehicle,

- a vehicle/object for which the variable (local: _bomb, global bomb) is never a string. It's position is given by getpos

 

My apology but i do not understand. i tried using getPoS, GetMarkerPos, Qotes, no qoutes, brackets, no brackets, nothing worked. Only after i tried the Shattens way i got some joy.

Share this post


Link to post
Share on other sites
Just now, Mirek said:

My apology but i do not understand. i tried using getPoS, GetMarkerPos, Qotes, no qoutes, brackets, no brackets, nothing worked. Only after i tried the Shattens way i got some joy.

Read the second part.

Share this post


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

bomb = ["brk_1","brk_2","brk_3","brk_4","brk_5"] call BIS_fnc_selectRandom;

bomb1 = "Bo_GBU12_LGB" createVehicle (getMarkerPos "bomb");

Just tried it it doesnt work. But thx anyway.

Share this post


Link to post
Share on other sites

@Mirek, let me try to explain... Let look on your code:

posbomb=["brk_1","brk_2","brk_3","brk_4","brk_5"];
bombpos = posbomb select (floor random 5);
bomb1 = "Bo_GBU12_LGB" createVehicle getPos "bombpos";

The first mistake is quotes around bombpos. You don't need them, because you don't have marker with that name, but variable that stores marker name.
The second mistake is using getPos command to get marker position. You should use getMarkerPos command instead.
Finally, this code should work:

posbomb=["brk_1","brk_2","brk_3","brk_4","brk_5"];
bombpos = posbomb select (floor random 5);
bomb1 = "Bo_GBU12_LGB" createVehicle getMarkerPos bombpos;

 

  • Like 1

Share this post


Link to post
Share on other sites
7 minutes ago, Mirek said:

Just tried it it doesnt work. But thx anyway.

I never wrote that! Could you read again:    bomb1 = "Bo_GBU12_LGB" createVehicle (getMarkerPos bomb) ?

  • Like 1
  • Thanks 1

Share this post


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

I never wrote that! Could you read again:    bomb1 = "Bo_GBU12_LGB" createVehicle (getMarkerPos bomb) ?

So removing the qotes is the thing?

 

  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Mirek said:

So removing the qotes is the thing?

 

The "thing" is to read the post above and try to understand what is a marker, an object, a variable.

A variable is a "container", so the content can be a marker (specific string) or an object (vehicle, thing, trigger, logic, agent), a location, a class... or an array [...] of what you want, or even a code {...}.

As soon as you define the variable, fill this container, you need to cope with the syntax of the commands you are using.

Syntax is always mentioned in BIKI: getMarkerPos  , getPos createVehicle , selectRandom...

  • Like 1

Share this post


Link to post
Share on other sites
17 hours ago, Mirek said:

So removing the qotes is the thing?

So, pierremgi above is trying to state the difference between the name of a variable and the name of a marker (or in the way presented and ArmA seems to "work", the marker "itself", represented by its name!).

 

Pierremgi is quite right in what states in their posts. The basic idea is to understand that the following line of code stores in a variable a string, which in turn corresponds to the name of the/a marker (modifying a bit pierremgi's snippet, but any other would do equally good)bomb = ["brk_1","brk_2","brk_3","brk_4","brk_5"] call BIS_fnc_selectRandom;

private _bomb = selectRandom ["brk_1","brk_2","brk_3","brk_4","brk_5"];

Please note a couple of things here. After this line of code is executed the variable _bomb will contain a string which will be one of the strings in the array on the right (either "brk_1", _brk_2", etc.) randomly selected (please note that I used the engine command selectRandom here, which is also proposed by pierremgi). The main takeaway here is to get the idea that a variable contains a string.

(Extra note: I made the variable _bomb private for no particular reason. Please remove the identifier "private" along with the '_' before the name of the variable to make it global if this is what is needed.)

 

Next, you want to use what you got here in order to create something (a bomb in this case) at the position of this marker. The command to create "something" is createVehicle as you already know of course. Without spending too much time to go through the syntax of the command (I believe you already know that) on the right-hand side of it you have to specify the position you want the object to be created. Now, the position you want is the position of the marker you got above and the command to get the position of a marker is getMarkerPos, which takes as argument the name of the marker in string format! This means that you have to pass it a string with the name of the marker you want to get the position of. Guess what..., you already got that with the code above! So, in order to pass the name of the marker you just have to pass the variable holding the name, _bomb that is. Thus, the correct line of code would be

 

Trying to differentiate between the two cases. One is

_bomb = "Bo_GBU12_LGB" createVehicle (getMarkerPos _bomb);

Please note here that I reuse the variable to store the created object. Feel free to change according to your needs. Now, if you write the following code you introduce an error (more like a bug I should say)

_bomb = "Bo_GBU12_LGB" createVehicle (getMarkerPos "_bomb");

What is not right here is that instead of the name of the marker you retrieved before and stored into the variable _bomb, you pass in a string containing "_bomb". Unless you have a marker named _bomb, nothing will happen. Maybe even worse, if you have a marker named _bomb the object will ALWAYS be created at its location, which of course is not the intended behaviour and it may, or may not, be harder to spot.

 

To summarise, the content of a variable with a certain name (for example variableWithStrangeName) is different than the content of a string (or the string itself if you prefer) "variableWithStrangeName". The former is a variable identified by its name and can contain pretty much anything, while the latter is a string containing a specific sequence of characters.

 

Hope this clarifies a bit the difference between the two and makes things easier for you to understand what the problem actually was.

 

Happy ArmA :).

  • Thanks 1

Share this post


Link to post
Share on other sites

OK I have read it 3 times really carefully, and that much got trough my thick skull: The thing before "=" is a variable, the tings after the "=" are the content of the variable. so the variable represents the theings after the "=" .  I have to give the "getMarkerPos" the string because it expets the string. from this i would gues i have to use the "" simbols because those mean it is a string but instead you say i should not use them. But if i dont use them then it is a variable or isnt it?

 

Nevermind: I tested it and it works without the "" marks, so i just dont use them when i use CreateVehicle together with Strings containing arrays.

Share this post


Link to post
Share on other sites

Well, you are pretty much on the right track... One minor thing you are "missing" here is that wherever you use a variable you actually use its content!

 

In effect, this means that when you write the following

"Bo_GBU12_LGB" createVehicle (getMarkerPos _bomb)

at the place of _bomb, what is actually passed is its content. If you recall, we have placed inside the variable _bomb the name of the marker of interest as a string. This means that the variable's content is a string corresponding to the name of the marker. Thus, effectively, by replacing the variable with its content you actually give the command the string representing the name of the marker.

 

Another, completely irrelevant example would be to add two numbers after having placed them inside a variable. The example in code looks like

// Define two variables
private _numOne = 12.5;
private _numTwo = -0.45;

// Perform some calculations
private _sum = _numOne + numTwo; // _sum now has inside it 12.5 + (-0.45) which is 12.05
private _diff = _numOne - numTwo; // _diff now has inside it 12.5 - (-0.45) which is 12.95
private _prod = _numOne * _numTwo; // _prod now has inside it 12.5 * (-0.45) which is -5.625
private _div = _numOne / _numTwo; // _div now has inside it 12.5 / (-0.45) which is approximately -27.77778

As you can see, in place of the variables are used their contents. The exact same thing happens no matter what the content of the variable is. For example, if you were to do the following

// Declare a variable that doesn't make sense to use
private _whatever = 0.1; // This is just a number

// Use it in the createVehicle command
private _obj = "Bo_GBU12_LGB" createVehicle (getMarkerPos _whatever);

Now, this is identical to calling the createVehicle command like

"Bo_GBU12_LGB" createVehicle (getMarkerPos 0.1)

This, of course, doesn't make sense and will produce an error, since the command getMarkerPos expects a string with the name of a marker. What I intended to show here is that in place of any variable its value is used. The variables are just placeholders given a specific name to be able to identify them. Consider the following example

// Define two DIFFERENT variables
private _numOne = 0.1;
private _numTwo = 0.1;

Now, both variables hold the same value, but they are effectively different values. Thus, changing one of them won't affect the other. They are stored in different memory locations on your computer. Nevertheless, whenever you use any of them in any command or calculation (such as addition, subtraction, etc.) you use their content and not their names.

 

In the exact same way when you pass a variable to a command, it is identical as to passing its content to the command. So, in the above code, when you use the variable _bomb in the getMarkerPos command you actually pass its content to the command. Recall again that the content of the said variable is a string (exactly what the command expects to get) and this is what is passed to the command. You could possibly pass a string "_bomb" but this would pass exactly that to the command, where if you pass the variable (or actually its content) to the command you will pass something like "brk_1", "brk_2", etc.

 

I hope this clarifies the thing for you because it is quite important to differentiate the notion of variables and their content and literals such as 0, 0.2, "This is just a string", 'a' (this is just a character).

 

Please don't hesitate to let anyone of us know if you need more help with it.

  • Thanks 1

Share this post


Link to post
Share on other sites

OK i probably understand.

 

  • Like 1

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

×