Blockland Welcome, Guest. Please login or register.
Did you miss your activation email?
June 23, 2018, 01:31:06 PM

Home Help Login Register
+  Blockland Forum
|-+  Blockland Forums
| |-+  Modification Help
| | |-+  [SOLVED] Adding Keybinds Breaks Game
Pages: [1]
Author Topic: [SOLVED] Adding Keybinds Breaks Game  (Read 647 times)
Platypi

« December 04, 2017, 11:41:21 PM »

I made a thread in the Help section about this earlier. I've recently been made aware that it's likely an error in my coding. Essentially, add-ons I create with keybinds tend to conflict with other add-ons. When they do, Blockland will load the same add-ons over and over on startup, until I decide to close the game.

Here's the code for an add-on I recently posted that has caused the problem for me and another user:
Code:
$remapDivision[$remapCount] = "Avatar Favorites";
for (%i = 1; %i < 10; %i++) {
$remapName[$remapCount] = "Switch to Avatar Favorite #" @ %i;
$remapCmd[$remapCount] = "AK_select" @ %i;
$remapCount++;
}
$remapName[$remapCount] = "Switch to Avatar Favorite #0";
$remapCmd[$remapCount] = "AK_select0";
$remapCount++;

function AK_select(%isDown, %i) {
if (%isDown) {
%fn = "config/client/AvatarFavorites/" @ %i @ ".cs";
if (isFile(%fn)) {
exec(%fn);
echo("Switched to avatar favorite #" @ %i);
}
else {
echo("No config found for avatar favorite #" @ %i);
}
clientCmdUpdatePrefs();
}
}

function AK_select1(%isDown) { AK_select(%isDown, 1); }
function AK_select2(%isDown) { AK_select(%isDown, 2); }
function AK_select3(%isDown) { AK_select(%isDown, 3); }
function AK_select4(%isDown) { AK_select(%isDown, 4); }
function AK_select5(%isDown) { AK_select(%isDown, 5); }
function AK_select6(%isDown) { AK_select(%isDown, 6); }
function AK_select7(%isDown) { AK_select(%isDown, 7); }
function AK_select8(%isDown) { AK_select(%isDown, 8); }
function AK_select9(%isDown) { AK_select(%isDown, 9); }
function AK_select0(%isDown) { AK_select(%isDown, 0); }

What could I be doing wrong? Nothing stands out to me.

I should also note that the same problem has occurred for other, even simpler add-ons, with single keybinds. Usually I just put something like this at the top of my code:
Code:
$remapDivision[$remapCount] = "Test Division";
$remapName[$remapCount] = "Test Keybind";
$remapCmd[$remapCount] = "TEST_callback";
$remapCount++;
« Last Edit: December 11, 2017, 01:12:36 AM by Platypi » Logged
Ad Bot

Full members do not see ads

Conan

« December 04, 2017, 11:54:00 PM »

try taking out the call to updateprefs
Logged
Platypi

« December 05, 2017, 12:00:36 AM »

try taking out the call to updateprefs
I'll try to see if I can replicate the issue again and do this. How would this be a problem on startup, though? Are commands in $remapCmd ran on startup?

EDIT: And... now I can't seem to replicate it. Let me see if the user mentioned below would be willing to test the add-on without clientCmdUpdatePrefs().



I should note, too, that removing the keybinding/$remap... section of the script does solve the problem (I recall trying it earlier).



Another user has supplied his console.log demonstrating the problem. It shows the same add-ons being loaded multiple times. File attached.

* console.log (41.36 KB - downloaded 37 times.)
« Last Edit: December 05, 2017, 12:12:52 AM by Platypi » Logged
Cowboy Dude

« December 05, 2017, 12:27:07 AM »

So I tested out the modified version of the add-on and I still can't start the game up when installed. I attached my console log.

* console.log (63.68 KB - downloaded 36 times.)
« Last Edit: December 05, 2017, 12:29:18 AM by Cowboy Dude » Logged
Shift Kitty

« December 05, 2017, 03:52:06 AM »

The only difference I can see in your code and other add-ons is that you don't have any sort of check to prevent the binds from applying multiple times.
Which... should in no shape or form cause this to happen but let me show you a way to at least fix that.

Code:
if(!$loadedAvatarFavsBinds)
{
$remapDivision[$remapCount] = "Avatar Favorites";
for (%i = 1; %i < 10; %i++) {
$remapName[$remapCount] = "Switch to Avatar Favorite #" @ %i;
$remapCmd[$remapCount] = "AK_select" @ %i;
$remapCount++;
}
$remapName[$remapCount] = "Switch to Avatar Favorite #0";
$remapCmd[$remapCount] = "AK_select0";
$remapCount++;
$loadedAvatarFavsBinds = 1;
}

function AK_select(%isDown, %i) {
if (%isDown) {
%fn = "config/client/AvatarFavorites/" @ %i @ ".cs";
if (isFile(%fn)) {
exec(%fn);
echo("Switched to avatar favorite #" @ %i);
}
else {
echo("No config found for avatar favorite #" @ %i);
}
clientCmdUpdatePrefs();
}
}

function AK_select1(%isDown) { AK_select(%isDown, 1); }
function AK_select2(%isDown) { AK_select(%isDown, 2); }
function AK_select3(%isDown) { AK_select(%isDown, 3); }
function AK_select4(%isDown) { AK_select(%isDown, 4); }
function AK_select5(%isDown) { AK_select(%isDown, 5); }
function AK_select6(%isDown) { AK_select(%isDown, 6); }
function AK_select7(%isDown) { AK_select(%isDown, 7); }
function AK_select8(%isDown) { AK_select(%isDown, 8); }
function AK_select9(%isDown) { AK_select(%isDown, 9); }
function AK_select0(%isDown) { AK_select(%isDown, 0); }


See if that makes a difference.
Logged
Platypi

« December 05, 2017, 02:01:31 PM »

The only difference I can see in your code and other add-ons is that you don't have any sort of check to prevent the binds from applying multiple times.
Which... should in no shape or form cause this to happen but let me show you a way to at least fix that.

Code:
if(!$loadedAvatarFavsBinds)
{
$remapDivision[$remapCount] = "Avatar Favorites";
for (%i = 1; %i < 10; %i++) {
$remapName[$remapCount] = "Switch to Avatar Favorite #" @ %i;
$remapCmd[$remapCount] = "AK_select" @ %i;
$remapCount++;
}
$remapName[$remapCount] = "Switch to Avatar Favorite #0";
$remapCmd[$remapCount] = "AK_select0";
$remapCount++;
$loadedAvatarFavsBinds = 1;
}

function AK_select(%isDown, %i) {
if (%isDown) {
%fn = "config/client/AvatarFavorites/" @ %i @ ".cs";
if (isFile(%fn)) {
exec(%fn);
echo("Switched to avatar favorite #" @ %i);
}
else {
echo("No config found for avatar favorite #" @ %i);
}
clientCmdUpdatePrefs();
}
}

function AK_select1(%isDown) { AK_select(%isDown, 1); }
function AK_select2(%isDown) { AK_select(%isDown, 2); }
function AK_select3(%isDown) { AK_select(%isDown, 3); }
function AK_select4(%isDown) { AK_select(%isDown, 4); }
function AK_select5(%isDown) { AK_select(%isDown, 5); }
function AK_select6(%isDown) { AK_select(%isDown, 6); }
function AK_select7(%isDown) { AK_select(%isDown, 7); }
function AK_select8(%isDown) { AK_select(%isDown, 8); }
function AK_select9(%isDown) { AK_select(%isDown, 9); }
function AK_select0(%isDown) { AK_select(%isDown, 0); }


See if that makes a difference.
This will at least make testing easier. I'll give it a shot later tonight.
Logged
Platypi

« December 10, 2017, 10:39:58 PM »

Sorry for taking so long to post an update (been really busy). I have heeded the suggestions of Shift Kitty and Kyuande.
Your mod is causing console errors because you put a local variable outside of a function. The %i is already used while the game boots up so you're setting it again which is why it causes the huge problem. Please fix this immediately.
Here's the code now:
Code:
if (!$AK_isLoaded) {
$remapDivision[$remapCount] = "Avatar Favorites";
for (%AK_i = 1; %AK_i < 10; %AK_i++) {
$remapName[$remapCount] = "Switch to Avatar Favorite #" @ %AK_i;
$remapCmd[$remapCount] = "AK_select" @ %AK_i;
$remapCount++;
}
$remapName[$remapCount] = "Switch to Avatar Favorite #0";
$remapCmd[$remapCount] = "AK_select0";
$remapCount++;
$AK_isLoaded = 1;
}

function AK_select(%isDown, %i) {
if (%isDown) {
%fn = "config/client/AvatarFavorites/" @ %i @ ".cs";
if (isFile(%fn)) {
exec(%fn);
echo("Switched to avatar favorite #" @ %i);
}
else {
echo("No config found for avatar favorite #" @ %i);
}
clientCmdUpdatePrefs();
}
}

function AK_select1(%isDown) { AK_select(%isDown, 1); }
function AK_select2(%isDown) { AK_select(%isDown, 2); }
function AK_select3(%isDown) { AK_select(%isDown, 3); }
function AK_select4(%isDown) { AK_select(%isDown, 4); }
function AK_select5(%isDown) { AK_select(%isDown, 5); }
function AK_select6(%isDown) { AK_select(%isDown, 6); }
function AK_select7(%isDown) { AK_select(%isDown, 7); }
function AK_select8(%isDown) { AK_select(%isDown, 8); }
function AK_select9(%isDown) { AK_select(%isDown, 9); }
function AK_select0(%isDown) { AK_select(%isDown, 0); }

I was able to replicate the original error, and independently verify that Kyuande's suggestion fixed the problem. Here's a link to the fixed add-on if anyone would like to verify that this fix works for others.
Logged
Cowboy Dude

« December 11, 2017, 12:05:32 AM »

Hey dude it worked for me!
Logged
Platypi

« December 11, 2017, 01:12:26 AM »

Hey dude it worked for me!
Awesome! I suppose I'll mark the topic as [SOLVED], as long as no one else has any more issues with it.
Logged
Pages: [1]  


Login with username, password and session length

Powered by SMF 1.1.20 | SMF © 2013, Simple Machines
Page created in 0.031 seconds with 18 queries.