Jump to content
dlegion

constantly display a variable on screen

Recommended Posts

hi all !
i wish to have a sort of "on screen constant scoreboard", that constantly displays a variable (in my case lets name it: "_Gcredits")
i really have no idea how do this, any help will be appreciated, thanks guys !
( i need it works on dedicated server, JIP and respawn)

Share this post


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

hi all !
i wish to have a sort of "on screen constant scoreboard", that constantly displays a variable (in my case lets name it: "_Gcredits")
i really have no idea how do this, any help will be appreciated, thanks guys !
( i need it works on dedicated server, JIP and respawn)

 

Check out tutorials on how to create a GUI. Or you can do it using a hint that stays in loop to make sure it stays on screen.

 

Cheers

Share this post


Link to post
Share on other sites

Hello @dlegion, maybe you're looking for something like this

missionNamespace setVariable ["Gcredits", 0, true];

with uiNamespace do {
	[] spawn {
		waitUntil {!isNull findDisplay 46};
		disableSerialization;

		_ctrl = findDisplay 46 ctrlCreate ["RscStructuredText", -1];
		_ctrl ctrlSetPosition [safeZoneX, safeZoneY + safeZoneH * 0.5, safeZoneW, safeZoneH * 0.04];
		_ctrl ctrlCommit 0;

		while {true} do {
			_ctrl ctrlSetStructuredText parseText format[
				"<t color='#8f8f8f' align='center' size='0.7'> Score:%1</t>",
				Gcredits
			];
		};
	};
};

I hope this helps

  • Like 1

Share this post


Link to post
Share on other sites

probably yeah!
where i have to put this code ?
thanks man !!


EDIT:
i tried adding it to "init.sqf" and then on "onPlayerRespawn.sqf", and i tried to define my variable with :  Gcredits = Garsenal getVariable "R3F_LOG_CF_credits";
but still dont work, it gives an error about "undefined Gcredits".
and i see a message: "score any" at aiming poin in center of screen. any way to move the display in the upper-right corner ?
thanks!!

Share this post


Link to post
Share on other sites

Your variable "Gcredits" is in missionNamespace not uiNamespace.

ask your variable with > missionNamespace getVariable "Gcredits" <.

 

Move your #control with ctrlSetPosition

Share this post


Link to post
Share on other sites

i'm sorry...but i dont understand where to put :(

Share this post


Link to post
Share on other sites

Its player-based and resistent, so put it in "initPlayerLocal.sqf".

Share this post


Link to post
Share on other sites

setvariable....set the variable or am i wrong ?
i need to read a variable, display on screen constantly, and when this variable changes, update the display!

Share this post


Link to post
Share on other sites
8 hours ago, dlegion said:

Gcredits = Garsenal getVariable "R3F_LOG_CF_credits";

Variable is global, so its in your missionNamespace.

 

21 hours ago, Nikander said:

with uiNamespace do {...

The script is running in uiNamespace, so "Gcredits" is unknown.

 

change this

21 hours ago, Nikander said:

while {true} do { _ctrl ctrlSetStructuredText parseText format[ "<t color='#8f8f8f' align='center' size='0.7'> Score:%1</t>", Gcredits ]; };

to

21 hours ago, Nikander said:

while {true} do { _ctrl ctrlSetStructuredText parseText format[ "<t color='#8f8f8f' align='center' size='0.7'> Score:%1</t>", missionNamespace getVariable "Gcredits" ]; };

and it works

 

 

  • Like 1

Share this post


Link to post
Share on other sites
22 hours ago, BlacKnightBK said:

@Nikander Dude, what does he do with the script you gave him?? Neither of us knows :(

 

Hello @BlacKnightBK, i'm not a clairvoyant but I recommed writing missionNamespace setVariable ["Gcredits", 0, true] in initServer.sqf if the variable is not player-based or missionNamespace setVariable ["Gcredits", 0], in initPlayerLocal.sqf if it is player-based or single-player.

 

Insert the rest , as corrected by Lucullus, in initPlayerLocal.sqf if nothing else comes to mind.

Share this post


Link to post
Share on other sites

ok...if i understand correctly:

initServer.sqf :
missionNamespace setVariable ["Gcredits", 0, true] ;

initPlayerLocal.sqf :

missionNamespace setVariable ["Gcredits", 0, true];

with uiNamespace do {
	[] spawn {
		waitUntil {!isNull findDisplay 46};
		disableSerialization;

		_ctrl = findDisplay 46 ctrlCreate ["RscStructuredText", -1];
		_ctrl ctrlSetPosition [safeZoneX, safeZoneY + safeZoneH * 0.5, safeZoneW, safeZoneH * 0.04];
		_ctrl ctrlCommit 0;

		while {true} do { _ctrl ctrlSetStructuredText parseText format[ "<t color='#8f8f8f' align='center' size='0.7'> Score:%1</t>",          missionNamespace getVariable "Gcredits" ]; }; 
	};
};

is it correct?  if not...i beg you, can you write the code please ? thanks guys !!
  • Like 1

Share this post


Link to post
Share on other sites

maybe i'm doing something wrong, but sadly it display a "score 0" message in the middle of screen :(
i wish to have it displayed in the upper right corner of screen (or at least in a corner) and display the actual value of my variable (was not set at 0 and will change during game)
 

Share this post


Link to post
Share on other sites
On 9.4.2017 at 0:17 PM, Lucullus said:

Move your #control with ctrlSetPosition

 

On 8.4.2017 at 7:06 PM, Nikander said:

_ctrl ctrlSetPosition [safeZoneX, safeZoneY + safeZoneH * 0.5, safeZoneW, safeZoneH * 0.04];

 

Move your #control whereever you want.

 

Try and learn is better as ask for finished scripts.

  • Like 1

Share this post


Link to post
Share on other sites

Just to help at little bit, all the screens are scaled by safeZone (more here) from 0 to 1, from upper left corner to lower right corner, regardless of dimension or ratio.

so, a display (control) will start at the middle of the screen with _ctrl  ctrlSetPosition [x, y, w, h] format.

The coordinate system seems to be hard, but test the 4 and 5 samples in my link.

 

If you want your variable updated with a whatever score, you need to make it "alive" by some script (for example, Gcredits= Gcredits + 1 for some condition). As you can see Gcredits here, is a global variable, not a local one as _Gcredits could be.

Remark: the syntax: missionNamespace setVariable ["Gcredits", 0, true];

is the same as: Gcredit = 0, publicVariable "Gcredit";

missionNameSpace is the space (variable recipient/context) by default. It makes sense to precise it when called from another name space (like UI).

 

So, the good question is: what is Gcredits? A personal score for a player >> you don't want to publicVariable it on each screens;

or a global variable, common and readable for everyboby >> you have to publicVariable it (or add true as 3rd argument of setVariable).

  • Like 1

Share this post


Link to post
Share on other sites

thanks man !
that help me understand !!
actually Gcredits is a global variable for a (side, G is for GUER side) factory, that has credits added at every "round win" by its side.
i already update it in another script called by a trigger, and when you open the factoary you already see how many credits are left, but i wished to have them constantly displayed (and updated at least at every round win),
so players can have an idea of credits of theyr faction and enemy faction at any given moment (i have also a Bcredits for BLUE side).
i'm sorry, i really do my best to learn, but i work 9-10 hours a day and have also other real life problems, and invest the few time left in learning this would mean finish a simple script in 2020...and i've already edited many others like R3F_LOG, SMS explosives and Zorylias 3D explosives and many others...its a too time consuming task :( 
thanks for your understanding guys !

  • 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

×