SRL Archive - General Botting Help

Playerform checkbox always returning false


TomTop

2015-02-18 15:27:57

Hey,

I have a problem where my checkboxes on the playerform always return false, no matter if they are checked or not, always false.

My code:

var
CHECKBOX: boolean;

procedure initPlayerForm();
begin
with playerForm do
begin
name := 'Player form';
scriptSettingsPath := AppPath + 'Scripts\Settings.txt';

editBoxLabels := ['World', 'number'];

editBoxDefaults := ['58', '8'];

checkBoxLabels := ['Checkbox'];

checkBoxDefaults := ['True'];

end;
end;

procedure declarePlayers();
begin
wait(randomRange(1000,2000));
players.setup(playerform.players);
currentPlayer := 0;

with players[0] do
begin
CHECKBOX := StrToBool(playerForm.players[0].settings[2]);
end;
end;

writeLn(CHECKBOX);

Don't know what's wrong :S

TomTop

2015-02-18 15:33:46

Sorry, please move this to SRL Development and Help.

3Garrett3

2015-02-18 16:11:04

From: TomTop
Sorry, please move this to SRL Development and Help.


Are you running this:


initPlayerForm();
runPlayerForm();

if (not playerForm.isScriptReady) then
exit;


Before you call declarePlayers?

TomTop

2015-02-18 16:34:21

From: 3Garrett3
Are you running this:


initPlayerForm();
runPlayerForm();

if (not playerForm.isScriptReady) then
exit;


Before you call declarePlayers?


Yeah I am, but instead of exit i have " terminatescript;".

3Garrett3

2015-02-18 16:55:24

From: TomTop
Yeah I am, but instead of exit i have " terminatescript;".


I don't see any immediate differences so I'll show you what works for me.


procedure declarePlayers();
var
i: integer;
begin
players.setup(playerForm.players);
currentPlayer := 0;

for i := 0 to high(players) do
with players[i] do
begin
integers[SET_RESTFOR] := strToInt(playerForm.players[i].settings[0]) * 60 * 1000;
integers[SET_RESTEVERY] := strToInt(playerForm.players[i].settings[1]) * 60 * 1000;
integers[SET_SLEEPFOR] := strToInt(playerForm.players[i].settings[2]) * 60 * 1000;
integers[SET_SLEEPEVERY] := strToInt(playerForm.players[i].settings[3]) * 60 * 1000;
integers[SET_SWITCHEVERY] := strToInt(playerForm.players[i].settings[4]) * 60 * 1000;
world := strToInt(playerForm.players[i].settings[5]);

booleans[SET_RESTING] := strToBool(playerForm.players[i].settings[6]);
booleans[SET_SLEEPING] := strToBool(playerForm.players[i].settings[7]);
end;

Debug := strToBool(playerForm.players[0].settings[8]);
end;

That's at the top of the script.

At the bottom of the script:


procedure initPlayerForm();
begin
with playerForm do
begin
name := '3Garrett3''s Evergreen Chopper'; // the title of the SPF, usually the name of your script
scriptHelpThread := ''; // a link to a help thread, if set to '' will link to my setup guide
scriptSettingsPath := ''; // where you want the settings file to be saved; saved in script's path by default

editBoxLabels := ['Minutes to Rest for', 'Minutes before Resting', 'Minutes to Sleep for', 'Minutes before Sleeping', 'Switch After', 'World']; // edit boxes are created for each array element
editBoxDefaults := ['30', '90', '180', '180', '180', '-1']; // optional default values for each edit box; array length must equal editBoxLabel length
checkBoxLabels := ['Break', 'Sleep', 'Debug']; // same as editBoxLabels but for check boxes
checkBoxDefaults := ['True', 'True', 'False'];
end;
end;

and


initPlayerForm();
runPlayerForm();

if (not playerForm.isScriptReady) then
terminateScript;

//...

declarePlayers();
setupSRL();

If everything matches your layout, it's something over my head.

TomTop

2015-02-19 08:31:19

From: 3Garrett3
~snip~


I just had a go, with your code, then I wanted to test it, with

writeln(players[CurrentPlayer].booleans[MULTI]);

But I get the error of "Error: Access violation at line 792".

Any ideas?

3Garrett3

2015-02-19 10:10:36

From: TomTop
I just had a go, with your code, then I wanted to test it, with

writeln(players[CurrentPlayer].booleans[MULTI]);

But I get the error of "Error: Access violation at line 792".

Any ideas?


Hmm, depending on what "MULTI" means, it could be that. But it's likely that the index doesn't exist. Either currentPlayer doesn't exist (maybe setupSRL hasn't been called?) or the MULTI index doesn't exist, meaning the form didn't properly run and save the variable.

TomTop

2015-02-19 11:47:12

From: 3Garrett3
Hmm, depending on what "MULTI" means, it could be that. But it's likely that the index doesn't exist. Either currentPlayer doesn't exist (maybe setupSRL hasn't been called?) or the MULTI index doesn't exist, meaning the form didn't properly run and save the variable.


The mutli is

booleans[MULTI] := strToBool(playerForm.players[i].settings[6]);
I call both declarePlayers (Which makes the currentPlayer), and then I call setupSRL.

:S

3Garrett3

2015-02-19 12:01:30

From: TomTop
The mutli is

booleans[MULTI] := strToBool(playerForm.players[i].settings[6]);
I call both declarePlayers (Which makes the currentPlayer), and then I call setupSRL.

:S


So you're calling it exactly like my main loop?

The only access violation I can think of is the MULTI index. Are you assigning a number to Multi? I assume it's a constant and you've assigned it like 0 or something right?

If that is returning the error then it's probably because the playerform is not properly initializing the variables and I'm not sure if I could help you in that case. @Olly is the only person that comes to mind when I brainstorm about who knows the playerform really well.

Olly, help? ^^

TomTop

2015-02-19 12:18:48

From: 3Garrett3
So you're calling it exactly like my main loop?

The only access violation I can think of is the MULTI index. Are you assigning a number to Multi? I assume it's a constant and you've assigned it like 0 or something right?

If that is returning the error then it's probably because the playerform is not properly initializing the variables and I'm not sure if I could help you in that case. @Olly is the only person that comes to mind when I brainstorm about who knows the playerform really well.

Olly, help? ^^


I have MULTI defined as a boolean.
If I PM you some snippets, would you be able to find the problem?

3Garrett3

2015-02-19 12:22:55

From: TomTop
I have MULTI defined as a boolean.
If I PM you some snippets, would you be able to find the problem?


MULTI has to be an integer.

It should be something like:

booleans[0] := strToBool(playerForm.players.settings[6]);

It is the index of an array, not a boolean. This is probably why it's throwing an access violation for you.

TomTop

2015-02-19 12:25:01

From: 3Garrett3
MULTI has to be an integer.

It should be something like:

booleans[0] := strToBool(playerForm.players.settings[6]);

It is the index of an array, not a boolean. This is probably why it's throwing an access violation for you.


But, Isn't a boolean a True or False?
I thought checkboxes returned True or False, not 1 or 0, never the less, I'll give it a try by changing my booleans to integers.

3Garrett3

2015-02-19 12:42:27

From: TomTop
But, Isn't a boolean a True or False?
I thought checkboxes returned True or False, not 1 or 0, never the less, I'll give it a try by changing my booleans to integers.


Sorry, I'm not explaining really well.

When you have the following:


players[currentPlayer].booleans[X]

The "booleans" is a type "Array of Boolean". That means you have to treat it like any other array. You can have a bunch of booleans in there, each being true or false. But the first boolean is #0 (booleans[0]) and the next is #1 , etc.

So when you are setting the players.booleans[X] variable, you have to set X to be an integer. You can set it to be 0 if it's the first boolean you use. You can set it to be 1 if it's the second, etc.

So:


players[currentPlayer].booleans[0]

This returns a boolean. The Boolean #0 in the player array is still a boolean, but you can't say:


players[currentPlayer].booleans[True]

Because that will cause an error in Simba.

TomTop

2015-02-19 12:48:37

From: 3Garrett3
Sorry, I'm not explaining really well.

When you have the following:


players[currentPlayer].booleans[X]

The "booleans" is a type "Array of Boolean". That means you have to treat it like any other array. You can have a bunch of booleans in there, each being true or false. But the first boolean is #0 (booleans[0]) and the next is #1 , etc.

So when you are setting the players.booleans[X] variable, you have to set X to be an integer. You can set it to be 0 if it's the first boolean you use. You can set it to be 1 if it's the second, etc.

So:


players[currentPlayer].booleans[0]

This returns a boolean. The Boolean #0 in the player array is still a boolean, but you can't say:


players[currentPlayer].booleans[True]

Because that will cause an error in Simba.


Oooh, I get it now. Thanks, I'll give it a shot!

3Garrett3

2015-02-19 12:50:37

From: TomTop
Oooh, I get it now. Thanks, I'll give it a shot!


Let me know how it goes!

TomTop

2015-02-21 09:27:06

From: 3Garrett3
Let me know how it goes!



Same error, access violation..

Olly

2015-02-21 10:06:04

{$i srl-6/srl.simba}
{$i srl-6/lib/misc/srlplayerform.simba}

var
CHECKBOX: boolean;

procedure initPlayerForm();
begin
with playerForm do
begin
name := 'Player form';
scriptSettingsPath := AppPath + 'Scripts\Settings.txt';

editBoxLabels := ['World', 'number'];

editBoxDefaults := ['58', '8'];

checkBoxLabels := ['Checkbox'];

checkBoxDefaults := ['True'];

end;
end;

procedure declarePlayers();
begin
wait(randomRange(1000,2000));
players.setup(playerform.players);
currentPlayer := 0;

with players[0] do
begin
CHECKBOX := StrToBool(playerForm.players[0].settings[2]);
end;
end;

begin
initPlayerForm();
runPlayerForm();

DeclarePlayers();

Writeln(CHECKBOX);
end.

Works fine for me.