Jump to content
Dj Rolnik

"IF" command with several results

Recommended Posts

Hey guys,

 

I am having some trouble with and IF command.

What I want to do is make a script behave differently depending on several conditions.

 

If one specific action takes place -> follow the script bit that is only under this IF

If the other action takes place -> follow the other route

etc, etc...

 

I managed to get something like this to work but am struggling with one thing (my suspicion is that I placed the waitUntil command in a wrong place but can't quite tell).

Basically the second condition triggers properly and it nicely ignores the hints that I placed in the first route but it does not seem to be ignoring the sleep commands that are placed in between the hints.

 

The second IF command triggers after the sleeps from the first command have fired even though I have not triggered the first IF.

 

It looks something like this:

 

    case "enter": {
        OutputText = InputText;
        waitUntil {
            if (((OutputText isEqualTo "361") && (name z == name z))) then {hint "Logging into the system"};
            closeDialog 0;
            InputText = "";
            sleep 1;
            true
        };
                if ((OutputText isEqualTo "361") && (name z == name z)) then {hint "Logging into the system."};
                sleep 1;
                if ((OutputText isEqualTo "361") && (name z == name z)) then {hint "Logging into the system.."};
                sleep 1;
                if ((OutputText isEqualTo "361") && (name z == name z)) then {hint "Logging into the system..."};
                sleep 1;
                if ((OutputText isEqualTo "361") && (name z == name z)) then {hint "Shutting down."};
                sleep 1;
                if ((OutputText isEqualTo "361") && (name z == name z)) then {hint "Shutting down.."};
                sleep 1;
                if ((OutputText isEqualTo "361") && (name z == name z)) then {hint "Shutting down..."};
                sleep 1.5;
                [terminal1,0] call BIS_fnc_dataTerminalAnimate;
                deleteVehicle box1;
            if !(OutputText isEqualTo "361") then {hint "bad2."};
            closeDialog 0;
            InputText = "";
            sleep 2;

 

Thanks a lot for any help - been trying to get this to work for a few days now and still cannot find a solution :(

 

Adam

Share this post


Link to post
Share on other sites

Most of the snippet is nonsensical.

 

Why repeat the same hint 3 times with a 1 second sleep inbetween?

Why all those name z == name z checks?

Why do you have a waitUntil with true at the end?

 

Did you write this yourself?

You'd probably be better off starting from scratch with easier stuff and take it step by step.

 

Cheers

Share this post


Link to post
Share on other sites

Hey,

 

I am a novice at scripting, I agree - that is why I am asking for any help. Hard to learn having to tear bits of knowledge from people on various forums and youtube videos.

I do realise that there are flaws with the script so if that is possible I would really appreciate someone who could suggest a better solution or at least help me understand how to improve this.

 

By the way, these are not the same hints - these are written as to simulate a progress happening (the dots at the end).

The true at the end of waitUntil is there due to Killzone's suggestion: https://community.bistudio.com/wiki/waitUntil

 

Cheers,

Adam

Share this post


Link to post
Share on other sites

i don't think "if" structure will work insine "waituntil". Try using if () then {}else{}; maybe? What is the expected outcome ? 

Share this post


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

i don't think "if" structure will work insine "waituntil". Try using if () then {}else{}; maybe? What is the expected outcome ? 

 

Let's simplify the hints a bit for the sake of this thread:

If the code used by the hacker equals 361 then the script should show the hint "GOOD"

If the code does not equal 361 but also does not equal nothing ("") then the script should throw hint "BAD" and close the terminal

If the code equals nothing ("") then the script would have to wait until either of the two above happens.

Share this post


Link to post
Share on other sites

I'd suggest using switch..do structure.. 

switch (_input) do
	{
	case 361 : {_hint = "good"};
	default {_hint = "bad"};
	};
if (_input isEqualTo "") exitWith {};

 

Share this post


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

i don't think "if" structure will work insine "waituntil". Try using if () then {}else{}; maybe? What is the expected outcome ? 

If structure is working fine inside waitUntil, what makes you think otherwise?

 

11 minutes ago, Dj Rolnik said:

Hey,

 

I am a novice at scripting, I agree - that is why I am asking for any help. Hard to learn having to tear bits of knowledge from people on various forums and youtube videos.

I do realise that there are flaws with the script so if that is possible I would really appreciate someone who could suggest a better solution or at least help me understand how to improve this.

 

By the way, these are not the same hints - these are written as to simulate a progress happening (the dots at the end).

The true at the end of waitUntil is there due to Killzone's suggestion: https://community.bistudio.com/wiki/waitUntil

 

Cheers,

Adam

 

 

3 minutes ago, Dj Rolnik said:

 

Let's simplify the hints a bit for the sake of this thread:

If the code used by the hacker equals 361 then the script should show the hint "GOOD"

If the code does not equal 361 but also does not equal nothing ("") then the script should throw hint "BAD" and close the terminal

If the code equals nothing ("") then the script would have to wait until either of the two above happens.

 

Well at least that's something to work with.

 

_outputOrWhatever = InputText;

if (parsenumber _outputOrWhatever isEqualTo 361) exitWith {hintsilent "Good."};
if (parsenumber _outputOrWhatever > 0) then {hintsilent "Bad."};
if (parsenumber _outputOrWhatever isEqualTo 0) then {hintsilent "Ugly."};

Parsenumber is pretty good for this, expects a string as input and returns 0 if the input is not a number.

Checking for a correct entry first, if that's not the case continuing with a check if the input is a valid number, and if not check if the input is anything else or an empty string.

 

Cheers

Share this post


Link to post
Share on other sites

Hey,

 

Thanks for both of your suggestions. I will try them out as soon as I can when I get back home.

A preemptive question tho. If those work, how can I add several actions as part of one result? For instance, if we take the solution provided by @Grumpy Old Man, and use this as an example:

if (parsenumber _outputOrWhatever isEqualTo 361) exitWith {hintsilent "Good."};

Can I add separate lines for subsequent hints separated by sleep, so that, in this case, the hints would signify the progress happening when hacking the terminal? Rough guess:

if (parsenumber _outputOrWhatever isEqualTo 361) exitWith {hintsilent "Good."};
sleep 1;
{hintsilent "Good1"};
sleep 1;
{hintsilent "Good2"};

etc?

I am worried that if the script is written like this, the sleep commands will still be picked up even if I do not trigger that particular IF.

 

Cheers,

Adam

Share this post


Link to post
Share on other sites

That's when you split everything up into smaller functions, here as an example a function to handle the hints depending on result:

TAG_fnc_hackingInTheNineties = {

	params ["_result"];

	if (_result isEqualTo "INVALID") exitWith {

		hintsilent "Invalid input! The device will blow up in an instant!";
		sleep 3;
		hintsilent "";
	};

	_timeOut = time + 5;
	_counter = 0;
	_dots = ["",".","..","..."];
	waitUntil {
	sleep 0.5;
	hintsilent format ["Logging into the system%1",_dots select _counter];
	_counter = _counter + 1;
	if (_counter > 3) then {_counter = 0};
	time > _timeOut;
	};

	sleep 0.5;
	hintsilent "Hacking in progress: 0%";
	sleep 0.5;

	_cancelAtPercent = round (50 + (random 49));

	if (_result isEqualTo "CORRECT") then {_cancelAtPercent = 100};

	for "_i" from 1 to _cancelAtPercent do {

		hintsilent format ["Hacking in progress: %1%2",_i,"%"];
		sleep 0.1;
		if (random 100 < 2.5) then {


			_timeOut = time + random [2,5,12];

			_symbols = ["$%§","§$%","%§$","%$§","!&?","&?!","?&!","!?%"];

			waitUntil {

				hintsilent format ["%1 %2 %3 %4 %5 %6\nUnknown dataset at %7%8!\nInterpolating!\n%9 %10 %11 %12 %13 %14",selectRandom _symbols,selectRandom _symbols,selectRandom _symbols,selectRandom _symbols,selectRandom _symbols,selectRandom _symbols,_i,"%",selectRandom _symbols,selectRandom _symbols,selectRandom _symbols,selectRandom _symbols,selectRandom _symbols,selectRandom _symbols];
				_counter = _counter + 1;
				if (_counter > 3) then {_counter = 0};
				if (time < _timeOut) then {sleep 0.1};
				time > _timeOut;

			};

		};

	};



	if (_result isEqualTo "INCORRECT") exitWith {

		sleep 0.5;
		hintsilent "Unauthorized login detected...";
		sleep 2.5;
		hintsilent "Shutting down...";
		sleep 3;
		hintsilent "";

	};

	sleep 0.5;
	hintsilent format ["Hacking in progress: 100%1!","%"];
	sleep 0.5;
	hintsilent format ["Hacking successfull!",""];
	sleep 3;
	hintsilent "";

};



_outputOrWhatever = "361";

if (parsenumber _outputOrWhatever isEqualTo 361) exitWith {

	["CORRECT"] spawn TAG_fnc_hackingInTheNineties;

};

if (parsenumber _outputOrWhatever > 0) then {

	["INCORRECT"] spawn TAG_fnc_hackingInTheNineties;

};

if (parsenumber _outputOrWhatever isEqualTo 0) then {

	["INVALID"] spawn TAG_fnc_hackingInTheNineties;

};


Play around with the _outputOrWhatever variable to check for correct result.

Also take into consideration that you can randomize the correct entry, so the number will be different every playthrough.

 

The hints good2 and good3 in your example will never appear since the code will be exited earlier if the input is correct.

 

Cheers

:

 

 

Share this post


Link to post
Share on other sites

Wow, that's comprehensive. I was slightly worried that it was going to end up being much more complicated than I originally assumed.

Will try it nevertheless. Hope that it works with the dialog keypad without problems.

 

Will get back here with the results.

 

Cheers!

Adam

Share this post


Link to post
Share on other sites

Hey all,

 

I haven't gotten to it for a while as I was pretty busy, but got some time today and tried to work something out with the solution provided by @Grumpy Old Man.

Unfortunately I failed. I seem to be unable to figure out how to implement this code into the script I have. When I use the code the keypad dialog seems to break completely.

I know I am asking for a lot but I feel that there is no way I can do it myself so maybe some kind soul would be able to take a look at the attached mission I am planning to make - maybe you can figure out how to incorporate the many ifs into the dialog script.

I genuinely appreciate any help but will understand if noone wants to do it by himself - that's fine, I know I am asking for a lot.

 

So just a recap on what I need:

(There is a bit of code that was included with the dialog script I downloaded. I only tried to add the many ifs into the script)

(The hacking of the terminal is supposed to fail irrespectively of whether the code is correct or not but only with slightly different results - it's a "decoy" terminal)

- I need to allow the hacking option to appear only for one player, the hacker - in this case called "z") (SEEMS DONE)

- I need the terminal to have the "Hack" action (DONE)
- I then need it to prompt with the "Open Keypad" action (DONE)

- I need it to launch the first scenario if the code input after pressing "Enter" equals "361". [hacking begins and progresses until a given percentage, and then shuts down] (SOMEWHAT DONE)
- I need it to launch the second scenario if the code input after pressing "Enter" does not equal "361". [hacking fails immediately and shuts down] (NOT DONE)

- I need it to launch the third scenario (basically waiting for the first or the second scenario to take place) if the code input after pressing "Enter" equals nothing (no input on the keypad, just pressing "Enter"). (NOT DONE)

- I need the Terminal to lose all actions after either the first or the second scenario have taken place (NOT DONE)

 

Preferably, I would like to keep the hint structure that I have in the AF_KP_fncs file. I know there are better ways to write the script and display the hints but what is there right now seems to work just as I need it to without too many complications.

So again, all comes down to putting the correct "IF" functions in the correct places within the script which I seem to be incapable of doing...

 

https://www.dropbox.com/s/yd6j1f6d3hp90jt/dialog.Altis.zip?dl=0

 

Thanks again for all the help,

Adam

Share this post


Link to post
Share on other sites

Problem solved. Managed to get some help from @Larrow who kindly agreed to do a bit of scripting for me - gotta learn that myself sooner rather than later. Thanks everyone for posting suggestions - means a lot to me as even though I'm not fluent in scripting, I feel I want to learn in a bit more now :)
 

Thanks again!

Adam

  • 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

×