Page 1 of 1

Replication trouble: can't access config variable on client

Posted: Mon Jan 14, 2019 2:08 am
by Dizzy
I'm trying to make the following UWindow dialog work properly:
Image

Notice the checkbox - when users tick this, a variable "bHasReadMessage=True" should be written to a UWindowExampleActor.ini file on their machine.

The problem is this config file is not being created on the client at all.

The variable is defined inside UWindowExampleActor.uc:

Code: Select all

class UWindowExampleActor expands Mutator config(UWindowExampleActor);
	
var config bool bHasReadMessage;
var PlayerPawn PP;

replication {
	reliable if(Role < ROLE_Authority)
		bHasReadMessage;
}

// [Stuff removed]

simulated function MarkAsRead() {

	bHasReadMessage = True;

	PP = PlayerPawn(Owner);
	PP.Say("DEBUG from UWindowExampleActor MarkAsRead())");
	PP.Say("bHasReadMessage: " $ string(bHasReadMessage));

	SaveConfig();

}
In ClientWindow.uc I am attempting to access the variable from the client's machine, and/or set it if the client has ticket the check box:

Code: Select all

class A_ClientWindow expands UMenuDialogClientWindow;

var UWindowExampleActor UWin;

// [Stuff removed]

simulated function MarkAsRead() {

	GetPlayerOwner().Say("DEBUG FROM A_ClientWindow MarkAsRead()");

	UWin.MarkAsRead();

}

simulated static function bool HasReadMessage() {
	return UWin.bHasReadMessage;
}

function Notify(UWindowDialogControl C, byte E) {

	local bool bRead;

	bRead = HasReadMessage();

	Super.Notify(C, E);

	switch(E) {

		case DE_Click:
			 switch(C) {
				case CloseButton:
					GetPlayerOwner().Say("DEBUG from A_ClientWindow:");
					GetPlayerOwner().Say("UWin.bHasReadMessage: " $ string(bRead));
					GetPlayerOwner().Say("CheckBox.bChecked: " $ string(CheckBox.bChecked));

					if (CheckBox.bChecked) {
						MarkAsRead();
					}

					ParentWindow.ParentWindow.Close();
				break;
			}
		break;

	}

}
I know I'm probably doing something completely wrong. Can somebody tell me what, please?

The code:
https://github.com/bunnytrack/UWindowEx ... er/Classes

Re: Replication trouble: can't access config variable on cli

Posted: Mon Jan 14, 2019 4:14 am
by Dizzy
With the kind help of PrinceOfFunky I was able to get this working (I think!).

I believe my fault was not actually spawning my "UWindowExampleActor" class from within "A_ClientWindow" before attempting to use it. I thought that simply defining it in a variable ("var UWindowExampleActor UWin;") at the top of the class was enough to instantiate an object of it, but it wasn't.

Also I added a few more "simulated" keywords to make some functions work on the client-side.

Thank you to PrinceOfFunky for helping painfully debug this.

I'll write a tutorial about creating a UWindow and post it here later so the next person who wants to create a simple message box doesn't have to go through all my pain.