Jump to content
Sign in to follow this  
_qor

loop text for progress bar

Recommended Posts

Hey there,

I want to have progress bar with a titleText, so I put it in a loop.

But although a condition turns false (distance to object), the text continous.



_talker = _this select 0;
_bother = _this select 1;



deleteVehicle H1box1;

deleteVehicle H1box2;

while {HOME1 == west AND !HOME1ammo AND (_talker distance _bother <10)} do {


titleText ["REARMING PROGRESS:[|         ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||        ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[|||       ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||      ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[|||||     ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||    ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[|||||||   ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||||  ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||||| ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||||||]COMPLETE", "PLAIN DOWN"];
titleFadeOut 1;


HOME1ammo = true;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo1_mark", [], 0, "NONE"];

H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo2_mark", [], 0, "NONE"];

	if (player == _bother) then {

	playSound "CodeBad"

	};

};

What am I doing wrong?

Edited by _qoR

Share this post


Link to post
Share on other sites

This is not working because the if-statement isnt in the loop. Having it in the loop would only check it at one time not during the whole loop...

Share this post


Link to post
Share on other sites

I actually was writing a big post to you about this a few days ago, only to realize that when I tried the script myself I was stuck. The main problem was that you were using a string as a progress bar instead of an integer.

So all I can explain now is that the reason why the text continues although the condition turns false is because you are looping the entire piece of code. From the first titleText all the way to PlaySound. That's the code that you keep repeating.

So I figured using a while {true} function with if() checks inside of it to check for the condition to be valid every 0.1-1 second or so would work. Though the problem is that there isn't a really "neat" way to do this because you're using text and not something that can be increased by using a formula. Something like:

while {true} do { 
if(HOME1 == west AND !HOME1ammo AND (_talker distance _bother <10)) then {  
_progress = _progress + 10; 
titleText [format ["REARMING PROGRESS: %1 PERCENT COMPLETE",_progress], "PLAIN DOWN"]; 
}; 
sleep 1; 
}; 

Instead you are using text, strings, which to my knowledge forces you to use a big lap of code, basically repeating the if() check before adding each bar ( " | | | " ) to the titleText.

I hope this somewhat helped you.

P.S. The code I wrote is in a more or less advisory form, if you are to use it you'll have to correct it and modify it.

Kind regards,

Sanchez

Share this post


Link to post
Share on other sites

Yaaah thats the problem!

So using strings is of course not impossible, but requires definitively more effort and thoughts!

Here is how I use your script-pattern now. I somehow feel that I use this in an inadequate way, but it works so far!

Perhaps you guys have some additional improvements for the script?!





_talker = _this select 0;
_bother = _this select 1;

_progress = 0;




while {alive _talker} do { 

if(HOME1 == west AND !HOME1ammo AND (_talker distance _bother <8)) then {

H1ammoRun = true;
_progress = _progress + 10;
titleText [format ["UNLOADING: %1 PERCENT COMPLETE", _progress], "PLAIN DOWN"];
titleFadeOut 2.5;

};



if (_talker distance _bother >8) exitWith {titleFadeOut 1; H1ammoRun = false};

if (_progress == 100 AND player != _bother) exitWith {

deleteVehicle H1box1;
deleteVehicle H1box2;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo1_mark", [], 0, "NONE"];
H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo2_mark", [], 0, "NONE"];

HOME1ammo = true;
H1ammoRun = false;

script = [] execVM "CHECKPOINTS\Ammo\HOME1\#1_H1gunnery.sqf";
script = [] execVM "CHECKPOINTS\Ammo\HOME1\#2_H1gunnery.sqf";

};

if (_progress == 100 AND player == _bother) exitWith {

playSound "CodeBad";

deleteVehicle H1box1;
deleteVehicle H1box2;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo1_mark", [], 0, "NONE"];
H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo2_mark", [], 0, "NONE"];

HOME1ammo = true;
H1ammoRun = false;

script = [] execVM "CHECKPOINTS\Ammo\HOME1\#1_H1gunnery.sqf";
script = [] execVM "CHECKPOINTS\Ammo\HOME1\#2_H1gunnery.sqf";



};


sleep 1;


};

Thanks to you PhonicStudios ;)

Edited by _qoR

Share this post


Link to post
Share on other sites
Yaaah thats the problem!

So using strings is of course not impossible, but requires definitively more effort and thoughts!

Here is how I use your script-pattern now. I somehow feel that I use this in an inadequate way, but it works so far!

Perhaps you guys have some additional improvements for the script?!





_talker = _this select 0;
_bother = _this select 1;

_progress = 0;




while {alive _talker} do { 

if(HOME1 == west AND !HOME1ammo AND (_talker distance _bother <8)) then {

H1ammoRun = true;
_progress = _progress + 10;
titleText [format ["UNLOADING: %1 PERCENT COMPLETE", _progress], "PLAIN DOWN"];
titleFadeOut 2.5;

};



if (_talker distance _bother >8) exitWith {titleFadeOut 1; H1ammoRun = false};

if (_progress == 100 AND player != _bother) exitWith {

deleteVehicle H1box1;
deleteVehicle H1box2;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo1_mark", [], 0, "NONE"];
H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo2_mark", [], 0, "NONE"];

HOME1ammo = true;
H1ammoRun = false;

script = [] execVM "CHECKPOINTS\Ammo\HOME1\#1_H1gunnery.sqf";
script = [] execVM "CHECKPOINTS\Ammo\HOME1\#2_H1gunnery.sqf";

};

if (_progress == 100 AND player == _bother) exitWith {

playSound "CodeBad";

deleteVehicle H1box1;
deleteVehicle H1box2;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo1_mark", [], 0, "NONE"];
H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo2_mark", [], 0, "NONE"];

HOME1ammo = true;
H1ammoRun = false;

script = [] execVM "CHECKPOINTS\Ammo\HOME1\#1_H1gunnery.sqf";
script = [] execVM "CHECKPOINTS\Ammo\HOME1\#2_H1gunnery.sqf";



};


sleep 1;


};

Thanks to you PhonicStudios ;)

Glad to hear you've got it working. If the script works as desired with no bugs, I'd suggest you keep it as it is.

The only thing I could suggest, but totally depends on your use of the script, is to change the condition in the while loop.

Only change it when this script is ran multiple times on the same system. Right now, if you run this script once (e.g. init.sqf) then it should work perfectly. If this script is triggered, from let's say an addAction, and the action can be done multiple times, you'll have multiple loops running at once for the entirety that '_talker' is alive.

In that case, perhaps change the condition to 'alive _talker && _progress < 100' which means the loop (and thus the script) will end after unloading is complete.

But remember, change it only if this script is run more than once.

Kind regards,

Sanchez

Share this post


Link to post
Share on other sites

But wouldnt the script end anyway because of exitWith? At least I hoped so!

And there is another question about the script.

I'd like to simplify the variables so I can copy the script and just need to change some names at the top.

But there is a problem with "H1WammoRun". When I do _run = H1WammoRun and then _run = true, I dont really change the actual variable but the _run variable.

Is there a way to do this?



_trig = HOME1W;
_ammo = HOME1Wammo;
_mark1 = "H1_ammo1_mark";
_mark2 = "H1_ammo2_mark";
[color="#B22222"]_run = H1WammoRun;[/color]


_talker = _this select 0;
_bother = _this select 1;

_progress = 0;




while {alive _talker AND alive _bother AND _progress < 100} do { 

if(_trig == west AND !_ammo AND (_talker distance _bother <8)) then {

[color="#B22222"]_run = true;[/color]
_progress = _progress + 10;
titleText [format ["UNLOADING: %1 PERCENT COMPLETE", _progress], "PLAIN DOWN"];
titleFadeOut 2.5;

};



if (_talker distance _bother >8) exitWith {titleFadeOut 1; H1WammoRun = false};

if (_progress == 100 AND player != _bother) exitWith {

deleteVehicle H1box1;
deleteVehicle H1box2;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo1_mark", [], 0, "NONE"];
H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo2_mark", [], 0, "NONE"];

_ammo = true;
H1WammoRun = false;

script = [] execVM "CHECKPOINTS\Ammo\HOME1\#1_H1gunnery.sqf";
script = [] execVM "CHECKPOINTS\Ammo\HOME1\#2_H1gunnery.sqf";

};

if (_progress == 100 AND player == _bother) exitWith {

playSound "CodeBad";

deleteVehicle H1box1;
deleteVehicle H1box2;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos _mark1, [], 0, "NONE"];
H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos _mark2, [], 0, "NONE"];

_ammo = true;
H1WammoRun = false;

script = [] execVM "CHECKPOINTS\Ammo\HOME1\#1_H1gunnery.sqf";
script = [] execVM "CHECKPOINTS\Ammo\HOME1\#2_H1gunnery.sqf";



};


sleep 1;


};


Edited by _qoR

Share this post


Link to post
Share on other sites

Oh yes, I may have overseen the exitWith functions.

I'm not sure what you want to achieve, if you want to change the value from the actual variable you're just going to have to use the actual variable.

You can do it by H1WammoRun = true; or by _run = true; H1WammoRun = _run;

Did this help?

Kind regards,

Mr. Sanchez

Share this post


Link to post
Share on other sites

_run should substitute the H1WammoRun variable in the script.

So I can change the variable's value on the top of the script and dont need to search for each position of the variable.

E.g. when the script should work for another checkpoint (in my scenario) called BASE2. So I would only change _run = Base2ammoRun once.

But at this certain point, I actually want to change the value of H1WammoRun, although I substituted it with _run.

So when I want to have H1WammoRun = true I cant type _run = true. Because this would mean that _run is not H1WammoRun anymore.

I'm kinda confused right now and cant simplify this description :D

Hope you'll get it xD

Share this post


Link to post
Share on other sites

I understand what you mean, but as long as you are using static variables (H1WammoRun, Base2ammoRun, etc..) the only way to change their value is by using them in the actual script.

For instance, starting value H1WammoRun = false; and _run = H1WammoRun;

in a script it changes, this is how you would change _run as well.

H1WammoRun = true; _run = H1WammoRun;

_run now holds the new updated value of H1WammoRun because we redefined it.

Is that what you meant or still something different?

Kind regards,

Sanchez

Share this post


Link to post
Share on other sites

Yah this is what I mean but this means that I have to type the variable name multiple times again.

I actually want to avoid that...

Share this post


Link to post
Share on other sites
Yah this is what I mean but this means that I have to type the variable name multiple times again.

I actually want to avoid that...

I wouldn't know, at this hour (2:19am) how one would change a variable value without calling the value. If there is a way, it's probably going to be more work than what you are trying to avoid.

Sometimes you may be asking too much ^^

Anyways, that's as far as I can help you.

Kind regards,

Sanchez

Share this post


Link to post
Share on other sites
If there is a way, it's probably going to be more work than what you are trying to avoid.

Possible! :D

Thought there is a common way to do that. Thanks for your help Phonic!

Share this post


Link to post
Share on other sites
Hey there,

I want to have progress bar with a titleText, so I put it in a loop.

But although a condition turns false (distance to object), the text continous.



_talker = _this select 0;
_bother = _this select 1;



deleteVehicle H1box1;

deleteVehicle H1box2;

while {HOME1 == west AND !HOME1ammo AND (_talker distance _bother <10)} do {


titleText ["REARMING PROGRESS:[|         ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||        ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[|||       ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||      ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[|||||     ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||    ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[|||||||   ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||||  ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||||| ]COMPLETE", "PLAIN DOWN"];
sleep 1;
titleText ["REARMING PROGRESS:[||||||||||]COMPLETE", "PLAIN DOWN"];
titleFadeOut 1;


HOME1ammo = true;

H1box1 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo1_mark", [], 0, "NONE"];

H1box2 = createVehicle ["USBasicWeapons_EP1", getMarkerPos "H1_ammo2_mark", [], 0, "NONE"];

	if (player == _bother) then {

	playSound "CodeBad"

	};

};

What am I doing wrong?

looks like you got this sorted by going a different route, but i thought i'de just throw this out as another option for you as well.

[] spawn {            
rearmTime = [];          
while {count rearmTime<10} do {                     
rearmTime=rearmTime+toArray "|";      
cutText [format["REARMING PROGRESS: [%1]",toString rearmTime], "PLAIN DOWN"]; 
if (count rearmTime == 10) then {cutText [format["REARMING PROGRESS: [%1] COMPLETED",toString rearmTime], "PLAIN DOWN"]; };  
sleep 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
Sign in to follow this  

×