Author Topic: Client variables don't properly update  (Read 772 times)

Ok, what am I doing wrong here? I thought this would be a simple script to toggle the chat on and off, but it's not working (with the exception of the keybind showing up). What am I doing wrong?

Code: [Select]
if (!$addedChatToggle)
{
$remapDivision[$remapCount] = "Chat";
$remapName[$remapCount] = "Toggle Chat On/Off";
$remapCmd[$remapCount] = "toggleChat";
$remapCount++;
$toggled = 1;
$addedChatToggle = true;
}
function toggleChat()
{
if($toggled)
{
%num = $Pref::Chat::MaxDisplayLines;
$Pref::Chat::MaxDisplayLines = 0;
$toggled = 0;
}
else if(!$Prefs::Chat::Toggled)
{
$Pref::Chat::MaxDisplayLines = %num;
$toggled = 1;
}
}

%num should be a global variable, not local. To avoid issues, you should also name it something unique.

%num should be a global variable, not local. To avoid issues, you should also name it something unique.
same with $toggled

True, don't know why I didn't think of that... Will switching to a global variable solve it?

If you haven't already tried it like you should have, yes it will.

At the end of the function, %num is deleted. Its value is lost. When the function is ran again, %num has no value because it hasn't been defined. Transferring this to a global variable will prevent it from being deleted at the end of the function, and will allow you to access it when the function is called again. This persistent variable is said to be in the global scope while your original implementation was confined to the local scope.

If you haven't already tried it like you should have, yes it will.

At the end of the function, %num is deleted. Its value is lost. When the function is ran again, %num has no value because it hasn't been defined. Transferring this to a global variable will prevent it from being deleted at the end of the function, and will allow you to access it when the function is called again. This persistent variable is said to be in the global scope while your original implementation was confined to the local scope.
Derp derp, you're right. Changing it, and thanks guys.