SRL Archive - Help and Support

Help with form?


Foundry

2014-08-31 14:25:56

So I have been working on my own include and have decided it's time to add a form. I got one working and decided it was time to integrate it into the library. That's when things got ugly…

This is the first file that compiles fine on it's own. This is the script that actually does stuff.
{$i wrl-1/clienthandler.simba}

const
MULTI_PRAY = 0;
MULTI_PRAY_N_CAST = 1;
MULTI_CAST = 2;
MULTI_IMPROVE = 3;
MULTI_CRAFT = 4;
MULTI_MINE = 5;
MULTI_FORGE = 6;
MULTI_FISH = 7;
MULTI_ARCHERY = 8;

VOID = 'lol';

var
task_pray, task_forge, task_prayncast, task_fish, task_cast, task_improve, task_mine, task_craft, task_archery: TIntFuncArray;
PrayerBox: TBox = [350, 350, 600, 575];
Prayers, Casts: Integer;

function skipWhileDoing(WhatToReturn: Integer = 0): Integer;
begin
if eventchat.doingActivity() or (not healthbar.isStaminaFull()) then
result := WhatToReturn;
end;

const
OPULENCE = 'nce';
BLESS = 'less';
TOUCH = 'ouch';

function spellToFavor(spell: String): Integer;
begin
case spell of
OPULENCE, BLESS: exit(10);
TOUCH: exit(30);
end;
end;

procedure moveAllMiners();
var
i: Integer;
begin
for i to high(WClients) do
if WClients[i].Script = MULTI_MINE then
WClients[i].Ints[3] := 1;
end;

function _pray(): Integer;
begin
PrayerBox.mouse();
pray(false);
inc(Prayers);
wait(randomrange(300, 500));
result := -1;
end;

function _skip(): Integer;
begin
wait(randomrange(200, 500));
result := skipWhileDoing(-1);
if (result <> -1) and (healthbar.getStatusLevel(WATER) < randomrange(75, 85)) and
WClients[ACI].__Drink then
WClients[ACI].drinkit();
end;

function _castIfCan(): Integer;
var
Slot: Integer;
begin
with WClients[ACI] do
begin
if healthbar.getStatusLevel(FAVOR) < (Ints[1] + random(4)) then
exit;
Bag.mouseFreeSpace();
wait(randomrange(200, 350));
Bag.update(true);
if Bag.isItemPresent(Strs[1]) then
Bag.deposit(Extra, backpack.getItemSlot(Strs[1], false));
if not Extra.isItemPresent(Strs[1]) then
begin
writeLn('Couldn''t find ' + Strs[1] + ' in the ' + Extra.Title + '.');
terminateScript();
end;
Bag.retrieve(Extra, Extra.getItemSlot(Strs[1]), 1);
wait(randomrange(1000, 1300));
Bag.mouseFreeSpace();
wait(randomrange(400, 650));
Bag.update(true);
Bag.mouseOptions(Bag.getItemSlot(Strs[1], false), ['ells', Strs[0]]);
wait(randomrange(400, 700));
inc(Casts);
exit(-1);
end;
end;

function _craft(): Integer;
var
i: Integer;
begin
with WClients[ACI] do
begin
_Crafting.create();
for i to 5 do
begin
wait(randomrange(200, 250));
if eventchat.doingActivity() then
exit(-1);
end;
end;
end;

function _checkRod(): Integer;
begin
with WClients[ACI] do
begin
Bag.mouseFreeSpace();
wait(randomrange(600, 800));
Bag.update(true);
if Bag.isItemPresent('unstrung') then
begin
writeLn('Broke a line...');
Active := false;
exit(-1);
end;
end;
end;

function _dropFish(): Integer;
var
Slots: TIntegerArray;
begin
with WClients[ACI] do
begin
if _EventLog.check(['carry the fish'], 1, true) then
begin
Bag.mouseFreeSpace();
wait(randomrange(700, 1000));
Bag.update(true);
Slots := Bag.getItemSlots(['brook trout', 'carp', 'catfish', 'dorado', 'herring',
'marlin', 'octopus', 'perch', 'pike', 'roach', 'sailfish',
'smallmouth bass', 'snook', 'tuna', 'white shark']);
Bag.dropItems(Slots);
wait(randomrange(300, 500));
end;
end;
end;

function _fish(): Integer;
begin
with WClients[ACI] do
begin
mouse(point(Ints[0], Ints[1]).rand(7));
wait(randomrange(10, 200));
fish(false);
Ints[2] := 1;
Timer.reset();
Timer.start();
exit(4);
end;
end;

function _shoot(): Integer;
begin
with WClients[ACI] do
begin
mouse(point(Ints[0], Ints[1]).rand(3));
wait(random(200));
fastClick(MOUSE_RIGHT);
wait(randomrange(800, 1000));
clickOptions(['rac']);
wait(randomrange(200, 500));
end;
end;

function _mine(): Integer;
var
i: Integer;
begin
with WClients[ACI] do
begin
if Ints[3] = 1 then
begin
_Movement.move(MFORWARD, 1.00);
Ints[3] := 0;
end;
if Ints[4] > randomrange(15, 20) then
begin
Bag.repairItems('pick');
Ints[4] := 0;
end;
mouse(point(Ints[0], Ints[1]).rand(10));
for i to Ints[2] - 1 do
begin
wait(randomrange(100, 300));
wmine(false);
Ints[4] := Ints[4] + 1;
end;
for i := 0 to 5 do
begin
wait(randomrange(200, 250));
if eventchat.doingActivity() then
exit(-1);
end;
if _EventLog.check(['far away'], 1, true) then
moveAllMiners();
end;
end;

function _waitForFish(): Integer; // FISH
var //
LumpSlot: Integer;
begin
writeLn('function _waitForFish(): Integer;');
with WClients[ACI] do
begin
if Ints[2] = 0 then
exit;
if Timer.getTime() > 7000 + random(500) then
begin
Timer.reset();
Timer.pause();
Ints[2] := 0;
exit(-1);
end else
exit(4);
end;
end;

function _getStuff(): Integer;
var
Products: TIntegerArray;
Slot, i: Integer;
begin
with WClients[ACI] do
begin
_Crafting.close();
if Bag.isItemPresent(Strs[0]) then
begin
Bag.deposit(Extra, Bag.getItemSlots(Strs[0], false)[0]);
wait(randomrange(700, 900));
Bag.mouseFreeSpace();
Bag.update(true);
end;

if Bag.isItemPresent(Strs[1]) and Boos[3] then
begin
Bag.deposit(Extra, Bag.getItemSlots(Strs[1], false)[0]);
wait(randomrange(700, 900));
Bag.mouseFreeSpace();
Bag.update(true);
end;

if Bag.isItemPresent(Strs[2]) then
begin
Products := Bag.getItemSlots(Strs[2], false);
if length(Products) > 1 then
begin
for i := 0 to high(Products) do
if Bag.Contents[Products[i] - 1].RareID = 0 then
begin
Slot := Products[i];
break;
end;
end else
Slot := Products[0];
Bag.deposit(Extra, Slot);
wait(randomrange(700, 900));
Bag.mouseFreeSpace();
Bag.update(true);
end;

if (Strs[4] <> VOID) and (Bag.isItemPresent(Strs[4])) then
begin
Bag.deposit(Extra, Bag.getItemSlots(Strs[4], false)[0]);
wait(randomrange(700, 900));
Bag.mouseFreeSpace();
Bag.update(true);
end;
Extra.mouseFreeSpace();
wait(randomrange(550, 800));
Extra.update(true);
if not Extra.isItemPresent(Strs[1]) then
begin
writeLn('Ran out of ' + Strs[1] + '.');
Active := false;
exit(-1);
end;
if (not Extra.isItemPresent(Strs[0])) and (Ints[3] = 1) then
begin
writeLn('Ran out of ' + Strs[0] + '.');
Active := false;
exit(-1);
end;
Bag.mouseFreeSpace();
Bag.update(true);
Bag.retrieve(Extra, Extra.getItemSlots(Strs[1])[0], Ints[0]);
if Boos[3] then
begin
wait(randomrange(500, 800));
Bag.retrieve(Extra, Extra.getItemSlots(Strs[0])[0], Ints[0]);
end;
Bag.mouseFreeSpace();
wait(randomrange(800, 1100));
Bag.update(true);
_Crafting.open();
if Bag.isItemPresent(Strs[0]) then
begin
_Crafting.setSlot(CB_SLOT_2, Bag.getItemSlots(Strs[0], false)[0], Bag);
wait(randomrange(200, 300));
if Boos[3] then
begin
Backpack.update(true);
_Crafting.setSlot(CB_SLOT_1, Bag.getItemSlots(Strs[1], false)[0], Bag);
end;
if Boos[1] then
_Crafting.combine(CB_COMBINE_2);
wait(randomrange(500, 1000));
end;
if Boos[2] then
begin
Bag.update(true);
Bag.repairItems(Strs[3]);
end;
_Crafting.create();
end;
end;

function _imp(): Integer;
begin
with WClients[ACI] do
begin


end;
end;

function _waitForHeat(): Integer;
var
LumpSlot: Integer;
begin
writeLn('function _waitForHeat(): Integer;');
with WClients[ACI] do
begin
if Ints[3] = 0 then
exit;
if Timer.getTime() > (Ints[1] * 1000) then
begin
Timer.reset();
Timer.pause();
Ints[3] := 0;
_Forge.mouseFreeSpace();
wait(randomrange(400, 700));
_Forge.update(true);
Bag.retrieve(_Forge, _Forge.getItemSlot(Strs[2]));
Bag.mouseFreeSpace();
wait(randomrange(400, 700));
Bag.update(true);
LumpSlot := Bag.getItemSlot(Strs[2]);
if Bag.Contents[LumpSlot - 1].Stack then
begin
_Crafting.open();
_Crafting.setSlot(CB_SLOT_2, Bag.getItemSlot(Strs[2]), Bag);
_Crafting.combine(CB_COMBINE_2);
_Crafting.close();
end;
end else
exit(2);
end;
end;

function _smith(): Integer;
var
LumpSlot, i: Integer;
begin
result := -1;
writeLn('function _smith(): Integer;');
with WClients[ACI] do
begin
if _Crafting.isOpen() then
begin
_Crafting.create();
for i to 5 do
begin
wait(randomrange(200, 250));
if eventchat.doingActivity() then
exit(-1);
end;
_Crafting.close();
Bag.mouseFreeSpace();
wait(randomrange(500, 800));
Bag.update(true);
if _EventLog.check(['must be glowing hot'], 2, true) then
exit({HEATMETAL}5);
exit({COOLPRODUCT}6);
end else begin
Bag.mouseFreeSpace();
wait(randomrange(500, 800));
Bag.update(true);
if not Bag.isItemPresent(Strs[2]) then
exit(4);
LumpSlot := Bag.getItemSlot(Strs[2]);
if Bag.Contents[LumpSlot - 1].Heat <> GLOWING_HOT then
begin
writeLn('The metal isn''t hot');
exit(5);
end;
_Crafting.open();
_Crafting.setSlot(CB_SLOT_2, LumpSlot, Bag);
exit(3);
end;
end;
end;

function _coolProduct(): Integer;
begin
writeLn('function _coolProduct(): Integer;');
with WClients[ACI] do
begin
Bag.mouseFreeSpace();
wait(randomrange(400, 800));
Bag.update(true);
_Dump.update(true);
Bag.deposit(_Dump, Bag.getItemSlot(Strs[3]), _Dump.getItemSlot(Strs[4]));
Ints[3] := 1;
Timer.reset();
Timer.start();
exit(1);
end;
end;

function _waitForCool(): Integer;
begin
writeLn('function _waitForCool(): Integer;');
with WClients[ACI] do
begin
if Ints[3] = 0 then
exit;
if Timer.getTime() > (Ints[0] * 1000) then
begin
Timer.reset();
Timer.pause();
Ints[3] := 0;
_Dump.mouseFreeSpace();
wait(randomrange(500, 800));
_Dump.update(true);
_Dump.expandContainers();
_Dump.mouseFreeSpace();
wait(randomrange(500, 800));
_Dump.update(true);
_Dump.deposit(Extra, _Dump.getItemSlot(Strs[3]));
exit(4);
end else
exit(1);
end; // STRS Codes
end; // 0 - heat forge
// 1 - cooling forge
function _getMetal(): Integer; // 2 - the name of the lump
var // 3 - the name of the item
LumpSlot: Integer; // 4 - the name of the container in the cooler
begin
writeLn('function _getMetal(): Integer;');
with WClients[ACI] do
begin
if not Extra.isItemPresent(Strs[2]) then
begin
Active := false;
writeLn('Some guy ran out of metal');
end;
Bag.retrieve(Extra, Extra.getItemSlot(Strs[2]), Ints[2]);
Bag.mouseFreeSpace();
wait(randomrange(500, 800));
Bag.update(true);
exit(5);
end;
end;

function _heatMetal(): Integer;
begin
writeLn('function _heatMetal(): Integer; ');
with WClients[ACI] do
begin
if Bag.isItemPresent(Strs[2]) then
Bag.deposit(_Forge, Bag.getItemSlot(Strs[2]));
Timer.reset();
Timer.start();
Ints[3] := 1;
exit(2);
end;
end;

procedure tasksInit(); //INTS CODES
begin //0 - for cool timer
setLength(task_pray, 2); //1 - for heat timer
task_pray[0] := _skip; //2 - how many lumps to get
task_pray[1] := _pray; //3 - boolean for timer
setLength(task_prayncast, 3);
task_prayncast[0] := _skip;
task_prayncast[1] := _castIfCan;
task_prayncast[2] := _pray;
setLength(task_cast, 2);
task_cast[0] := _skip;
task_cast[1] := _castIfCan;
setLength(task_craft, 3);
task_craft[0] := _skip;
task_craft[1] := _craft;
task_craft[2] := _getStuff;
setLength(task_fish, 5);
task_fish[0] := _skip;
task_fish[1] := _checkRod;
task_fish[2] := _dropFish;
task_fish[3] := _fish;
task_fish[4] := _waitForFish;
setLength(task_forge, 7);
task_forge[0] := _skip;
task_forge[1] := _waitForCool;
task_forge[2] := _waitForHeat;
task_forge[3] := _smith;
task_forge[4] := _getMetal;
task_forge[5] := _heatMetal;
task_forge[6] := _coolProduct;
setLength(task_mine, 2);
task_mine[0] := _skip;
task_mine[1] := _mine;
setLength(task_archery, 2);
task_archery[0] := _skip;
task_archery[1] := _shoot;
end;

procedure clientInit(var target: TWurmClient);
var
Answer: String;
begin
mouse(point(randomrange(0, ResX), randomrange(-24, -20)));
with target do // I know a lot of this is redundant but I will be adding
begin // on later.
switchTo();
initMenu(INVENTORY);
case Script of
MULTI_PRAY: begin
_Toolset.SetupWater := true;
_Toolset.init();
Queue := task_pray;
end;
MULTI_PRAY_N_CAST, MULTI_CAST: begin
initMenu(CRATE);
Bag.activateItem('statuette');
_Toolset.init();
_EventLog.init(EVENT, 10);
setLength(Ints, 2);
Ints[1] := round((spellToFavor(Strs[0]) / Ints[0]) * 100) + 1;
if Script = MULTI_PRAY_N_CAST then
Queue := task_prayncast //INTS for IMPING
else //0 - What type of imping?
Queue := task_cast; //1 -
end; //
MULTI_IMPROVE: begin //STRS for IMPING
_Belt.init(); //0 - Name of menu of item.
_Toolset.init(); //1 - Name of the item to be improved.
if Strs[0] = INVENTORY then
ImpSlots := Bag.getItemSlots(Strs[1])
else begin
initMenu(Strs[0]);
ImpSlots := Extra.getItemSlots(Strs[1]);
Bag := Extra;
end;
end;
MULTI_FORGE: begin
initMenu(BSB);
_EventLog.init(EVENT, 10);
_Forge.init(Strs[0]);
_Dump.init(Strs[1]);
_Crafting.init();
Queue := task_forge;
ResumeCounter := 3;
setLength(Ints, 4);
Ints[3] := 0;
end;
MULTI_MINE: begin
_Movement.init();
_EventLog.init(EVENT, 10);
Bag.activateItem('pick');
Queue := task_mine;
setLength(Ints, 5);
end;
MULTI_CRAFT: begin
_Toolset.init();
initMenu(BSB);
_Crafting.init();
if Strs[3] <> VOID then
begin
_Crafting.open();
if Bag.isItemPresent(Strs[3]) then
_Crafting.setSlot(CB_SLOT_1, Bag.getItemSlots(Strs[3], false)[0], Bag)
else begin
writeLn('Get this guy the right tool');
terminateScript();
end;
end;
if not Extra.isItemPresent(Strs[1]) then
begin
writeLn('You need to put ' + Strs[1] + ' in your bsb!');
terminateScript();
end;
ResumeCounter := 2;
Queue := task_craft;
end;
MULTI_FISH: begin
if not Bag.activateItem('fishing') then
begin
writeLn('You need to give this guy a rod, he can''t fish with his hands...');
terminateScript();
end; // INTS for MULTI_FISH
_EventLog.init(EVENT, 10);
Queue := task_fish;
setLength(Ints, 3);
end;
MULTI_ARCHERY: begin
if not Bag.activateItem('bow') then
begin
writeLn('You need to give this guy a bow, he can''t throw the arrows...');
terminateScript();
end;
Queue := task_archery;
setLength(Ints, 3);
end;
end;
end;
end;

procedure addPlayer(Name: String; _Ints: TIntegerArray; _Strs: TStringArray; _Boos: TBoolArray; ScriptID: Integer);
var
i: Integer;
begin
with WClients[WClients.getNameIndex(Name)] do
begin
Script := ScriptID;
Ints := _Ints;
Strs := _Strs;
Boos := _Boos;
__Drink := Boos[0];
end;
clientInit(WClients[WClients.getNameIndex(Name)]);
end;

But when I try to include it in the form that also runs fine by itself(before I add variables from the other one)…
{$i multimisc.simba}

type
TPlayerData = record
Ints: TIntegerArray;
Strs: TStringArray;
ScriptID: Integer;
Boos: TBoolArray;
end;

TPlayerSettings = record
Name: String;
Top, NextLeft, NextLeftCheckboxes: Integer;
lbl_Name: TLabel;
cbo_Script: TComboBox;
chk_Array: array of TCheckbox;
edt_Array: array of TEdit;
lbl_Array: array of TLabel;
OptionsDisplayed: Boolean;
Data: TPlayerData;
end;

var
ScriptIDs: TStringArray = ['Crafting', 'smith', 'etc'];
mainform: TForm;
btn_AddCharacter, btn_ShowOptions, btn_Start, btn_Save: TButton;
edt_AddCharacter: TEdit;
lbl_AddCharacter: TLabel;
debugbox: TMemo;
Players: array of TPlayerSettings;
ReadyToGo: Boolean;

procedure formWriteln(str: Variant);
begin
debugbox.getLines().add(toStr(str));
end;

procedure TPlayerSettings.addEDT(Title: String);
var
i: Integer;
begin
i := length(edt_Array);
setLength(edt_Array, i + 1);
edt_Array[i].init(mainform);
with edt_Array[i] do
begin
setParent(mainform);
setLeft(NextLeft);
setTop(Top - 3);
setCaption(Title);
setWidth(80);
end;
NextLeft := NextLeft + 85;
end;

procedure TPlayerSettings.addCHK(Title: String);
var
i: Integer;
begin
i := length(lbl_Array);
if i = 0 then
NextLeftCheckboxes := lbl_Name.getLeft() + 10;
setLength(lbl_Array, i + 1);
lbl_Array[i].init(mainform);
with lbl_Array[i] do
begin
setParent(mainform);
setLeft(NextLeftCheckboxes);
setTop(Top + 25);
setCaption(Title);
setWidth(80);
end;

setLength(chk_Array, i + 1);
chk_Array[i].init(mainform);
with chk_Array[i] do
begin
setParent(mainform);
setLeft(NextLeftCheckboxes + lbl_Array[i].getWidth() + 2);
setTop(Top + 24);
end;
NextLeftCheckBoxes := NextLeftCheckboxes + lbl_Array[i].getWidth() + chk_Array[i].getWidth() + 20;
end;

function TPlayerSettings.parse(): Boolean;
var
i: Integer;
begin
setLength(Data.Boos, length(chk_Array));
for i to high(chk_Array) do
Data.Boos[i] := (chk_Array[i].getState() = cbChecked);
case cbo_Script.getText() of
'Crafting': begin
Data.ScriptID = MULTI_CRAFT;
setLength(Data.Strs, 4);
setLength(Data.Ints, 1);
for i := 0 to 3 do
Data.Strs[i] := edt_Array[i].getText();
try
Data.Ints[0] := strToInt(edt_Array[4].getText());
except
exit;
end;
end;
'nextone': begin



end;
end;
result := true;
end;

procedure saveOptions(sender: TObject); native;
var
i: Integer;
begin
end;

procedure startScript(sender: TObject); native;
var
i: Integer;
begin
for i to high(Players) do
if not Players[i].parse() then
begin
formWriteLn('Check your stuff and submit it right next time!');
exit;
end;
ReadyToGo := true;
end;

procedure refreshOptions(sender: TObject); native;
var
i: Integer;
begin
for i := 0 to high(Players) do
with Players[i] do
begin
if not OptionsDisplayed then
begin
case cbo_Script.getText() of
'Crafting': begin
addEDT('Mat 1 Name');
addEDT('Mat 2 Name');
addEDT('Tool Name');
addEDT('Product Name');
addEDT('Waste Name');
addEDT('Amount Withdrawn');
addCHK('Drink Water?');
addCHK('Combine?');
addCHK('Repair Tool?');
addCHK('Assembling?');

end;
else
exit;
end;
OptionsDisplayed := true;
end;
end;
end;

procedure TPlayerSettings.init(_Name: String);
var
i: Integer;
begin
Name := _Name;
Top := edt_AddCharacter.getTop() + edt_AddCharacter.getHeight() + 10 + ((length(Players) - 1) * 60);

lbl_Name.init(mainform);
with lbl_Name do
begin
setParent(mainForm);
setLeft(edt_AddCharacter.getLeft() + 5);
setTop(Top);
setWidth(80);
setCaption(Name + ':');
end;

cbo_Script.init(mainform);
with cbo_Script do
begin
setParent(mainform);
setLeft(lbl_Name.getLeft() + lbl_Name.getWidth() + 10);
setTop(Top - 3);
setWidth(125);
setCaption('Select a scipt!');
for i := 0 to high(ScriptIDs) do
addItem(ScriptIDs[i], nil);
end;

NextLeft := cbo_Script.getLeft() + 135;
end;

procedure handleCharacterName(sender: TObject); native;
var
i: Integer;
NewName: String;
begin
NewName := edt_AddCharacter.getText();
if NewName = '' then
formwriteln('You didn''t write anything!')
else begin
for i := 0 to high(Players) do
if NewName = Players[i].Name then
begin
formWriteLn('That name already exists');
exit;
end;
setLength(Players, length(Players) + 1);
Players[high(Players)].init(NewName);
formWriteLn('Added ' + NewName + ' to character list.');
end;
end;

procedure initform(); native;
begin
mainForm.init(nil);
with mainForm do
begin
setWidth(700);
setHeight(600);
setCaption('Settings');
setPosition(poScreenCenter);
end;

debugbox.init(mainForm);
with debugbox do
begin
setParent(mainForm);
setLeft(mainform.getLeft() + 9);
setWidth(mainForm.getWidth() - 18);
setTop(490);
setHeight(100);
setScrollBars(ssAutoBoth);
end;

lbl_AddCharacter.init(mainform);
with lbl_AddCharacter do
begin
setParent(mainForm);
setTop(5);
setLeft(10);
setWidth(125);
setCaption('Add a player');
end;

edt_AddCharacter.init(mainForm);
with edt_AddCharacter do
begin
setParent(mainForm);
setLeft(lbl_AddCharacter.getLeft() - 5);
setTop(lbl_AddCharacter.getTop() + lbl_AddCharacter.getHeight() + 1);
setHeight(25);
setWidth(lbl_AddCharacter.getWidth());
end;

btn_AddCharacter.init(mainForm);
with btn_AddCharacter do
begin
setParent(mainForm);
setLeft(edt_AddCharacter.getLeft() + edt_AddCharacter.getWidth() + 5);
setTop(edt_AddCharacter.getTop() + 1);
setHeight(21);
setWidth(45);
setCaption('Add');
setOnClick(handleCharacterName);
end;

btn_ShowOptions.init(mainForm);
with btn_ShowOptions do
begin
setParent(mainForm);
setLeft(mainform.getWidth() - 200);
setTop(debugbox.getTop() - 30);
setHeight(21);
setWidth(85);
setCaption('Show Options');
setOnClick(refreshOptions);
end;

btn_Save.init(mainForm);
with btn_Save do
begin
setParent(mainForm);
setLeft(mainform.getWidth() - 110);
setTop(debugbox.getTop() - 30);
setHeight(21);
setWidth(50);
setCaption('Save');
setOnClick(saveOptions);
end;

btn_Start.init(mainForm);
with btn_Start do
begin
setParent(mainForm);
setLeft(mainform.getWidth() - 55);
setTop(debugbox.getTop() - 30);
setHeight(21);
setWidth(40);
setCaption('Go');
setOnClick(refreshOptions);
end;

formWriteLn('Add a character name to get started...');
mainForm.showModal();
mainForm.free();
end;

procedure getPlayerInfo();
begin
sync(initform);
end;

var
i: Integer;

begin
getPlayerInfo();
if not ReadyToGo then
terminateScript();
tasksInit();
WClients.init(WClients[0].Name);
setupImpBMPs();
for i to high(Players) do
with Players[i] do
addPlayer(Name, Data.Ints, Data.Strs, Data.Boos, Data.ScriptID);
repeat
for i := 0 to high(WClients) do
begin
WClients[i].switchTo();
wait(randomrange(450, 750));
WClients[i].cycle();
wait(randomrange(450, 750));
end;
until false;
end.

I get this error upon compiling the second one:
Exception in Script: Variable expected at line 1, column 29 at line 1, column 29

I am trying to make a form that will pass the information to the first script. I make the form and try to include multimisc.simba(the first file) and I get the above error. The fact that the first one compiles fine by itself means the problem is something to do with these two files. I have tried moving them around and doing it vice versa without any results.

Sin

2014-08-31 14:39:32

program myScriptname;?

Foundry

2014-08-31 14:40:29

From: Sin
program myScriptname;?


Forgot to mention I tried that.

Brandon

2014-08-31 14:53:24

Line 94 needs to be:


Data.ScriptID := MULTI_CRAFT;

Assignment operator.. You're mixing it up with const initialisation operator.

Somewhere in your script needs a var but you might be passing a literal or a const.. clientInit takes a var.. make sure that you're not passing it anything else (const or literal).

You're going to have to narrow it down since we cannot compile it ourselves..

Foundry

2014-08-31 15:07:32

From: Brandon
Line 94 needs to be:


Data.ScriptID := MULTI_CRAFT;

Assignment operator.. You're mixing it up with const initialisation operator.

Somewhere in your script needs a var but you might be passing a literal or a const.. clientInit takes a var.. make sure that you're not passing it anything else (const or literal).

You're going to have to narrow it down since we cannot compile it ourselves..


Thanks, I didn't catch that. If I need to post the include I will, I'll just need this moved up to SRL Members+.

Worked for another 10 minutes on trying to fix it and I double checked if the form compiles by itself and it does. It is only these commented sections that cause the error:
//{$i multimisc.simba}

type
TPlayerData = record
Ints: TIntegerArray;
Strs: TStringArray;
ScriptID: Integer;
Boos: TBoolArray;
end;

TPlayerSettings = record
Name: String;
Top, NextLeft, NextLeftCheckboxes: Integer;
lbl_Name: TLabel;
cbo_Script: TComboBox;
chk_Array: array of TCheckbox;
edt_Array: array of TEdit;
lbl_Array: array of TLabel;
OptionsDisplayed: Boolean;
Data: TPlayerData;
end;

var
ScriptIDs: TStringArray = ['Crafting', 'smith', 'etc'];
mainform: TForm;
btn_AddCharacter, btn_ShowOptions, btn_Start, btn_Save: TButton;
edt_AddCharacter: TEdit;
lbl_AddCharacter: TLabel;
debugbox: TMemo;
Players: array of TPlayerSettings;
ReadyToGo: Boolean;

procedure formWriteln(str: Variant);
begin
debugbox.getLines().add(toStr(str));
end;

procedure TPlayerSettings.addEDT(Title: String);
var
i: Integer;
begin
i := length(edt_Array);
setLength(edt_Array, i + 1);
edt_Array[i].init(mainform);
with edt_Array[i] do
begin
setParent(mainform);
setLeft(NextLeft);
setTop(Top - 3);
setCaption(Title);
setWidth(80);
end;
NextLeft := NextLeft + 85;
end;

procedure TPlayerSettings.addCHK(Title: String);
var
i: Integer;
begin
i := length(lbl_Array);
if i = 0 then
NextLeftCheckboxes := lbl_Name.getLeft() + 10;
setLength(lbl_Array, i + 1);
lbl_Array[i].init(mainform);
with lbl_Array[i] do
begin
setParent(mainform);
setLeft(NextLeftCheckboxes);
setTop(Top + 25);
setCaption(Title);
setWidth(80);
end;

setLength(chk_Array, i + 1);
chk_Array[i].init(mainform);
with chk_Array[i] do
begin
setParent(mainform);
setLeft(NextLeftCheckboxes + lbl_Array[i].getWidth() + 2);
setTop(Top + 24);
end;
NextLeftCheckBoxes := NextLeftCheckboxes + lbl_Array[i].getWidth() + chk_Array[i].getWidth() + 20;
end;

function TPlayerSettings.parse(): Boolean;
var
i: Integer;
begin
setLength(Data.Boos, length(chk_Array));
for i to high(chk_Array) do
Data.Boos[i] := (chk_Array[i].getState() = cbChecked);
case cbo_Script.getText() of
'Crafting': begin
//Data.ScriptID := MULTI_CRAFT;
setLength(Data.Strs, 4);
setLength(Data.Ints, 1);
for i := 0 to 3 do
Data.Strs[i] := edt_Array[i].getText();
try
Data.Ints[0] := strToInt(edt_Array[4].getText());
except
exit;
end;
end;
'nextone': begin



end;
end;
result := true;
end;

procedure saveOptions(sender: TObject); native;
var
i: Integer;
begin
end;

procedure startScript(sender: TObject); native;
var
i: Integer;
begin
for i to high(Players) do
if not Players[i].parse() then
begin
formWriteLn('Check your stuff and submit it right next time!');
exit;
end;
ReadyToGo := true;
end;

procedure refreshOptions(sender: TObject); native;
var
i: Integer;
begin
for i := 0 to high(Players) do
with Players[i] do
begin
if not OptionsDisplayed then
begin
case cbo_Script.getText() of
'Crafting': begin
addEDT('Mat 1 Name');
addEDT('Mat 2 Name');
addEDT('Tool Name');
addEDT('Product Name');
addEDT('Waste Name');
addEDT('Amount Withdrawn');
addCHK('Drink Water?');
addCHK('Combine?');
addCHK('Repair Tool?');
addCHK('Assembling?');

end;
else
exit;
end;
OptionsDisplayed := true;
end;
end;
end;

procedure TPlayerSettings.init(_Name: String);
var
i: Integer;
begin
Name := _Name;
Top := edt_AddCharacter.getTop() + edt_AddCharacter.getHeight() + 10 + ((length(Players) - 1) * 60);

lbl_Name.init(mainform);
with lbl_Name do
begin
setParent(mainForm);
setLeft(edt_AddCharacter.getLeft() + 5);
setTop(Top);
setWidth(80);
setCaption(Name + ':');
end;

cbo_Script.init(mainform);
with cbo_Script do
begin
setParent(mainform);
setLeft(lbl_Name.getLeft() + lbl_Name.getWidth() + 10);
setTop(Top - 3);
setWidth(125);
setCaption('Select a scipt!');
for i := 0 to high(ScriptIDs) do
addItem(ScriptIDs[i], nil);
end;

NextLeft := cbo_Script.getLeft() + 135;
end;

procedure handleCharacterName(sender: TObject); native;
var
i: Integer;
NewName: String;
begin
NewName := edt_AddCharacter.getText();
if NewName = '' then
formwriteln('You didn''t write anything!')
else begin
for i := 0 to high(Players) do
if NewName = Players[i].Name then
begin
formWriteLn('That name already exists');
exit;
end;
setLength(Players, length(Players) + 1);
Players[high(Players)].init(NewName);
formWriteLn('Added ' + NewName + ' to character list.');
end;
end;

procedure initform(); native;
begin
mainForm.init(nil);
with mainForm do
begin
setWidth(700);
setHeight(600);
setCaption('Settings');
setPosition(poScreenCenter);
end;

debugbox.init(mainForm);
with debugbox do
begin
setParent(mainForm);
setLeft(mainform.getLeft() + 9);
setWidth(mainForm.getWidth() - 18);
setTop(490);
setHeight(100);
setScrollBars(ssAutoBoth);
end;

lbl_AddCharacter.init(mainform);
with lbl_AddCharacter do
begin
setParent(mainForm);
setTop(5);
setLeft(10);
setWidth(125);
setCaption('Add a player');
end;

edt_AddCharacter.init(mainForm);
with edt_AddCharacter do
begin
setParent(mainForm);
setLeft(lbl_AddCharacter.getLeft() - 5);
setTop(lbl_AddCharacter.getTop() + lbl_AddCharacter.getHeight() + 1);
setHeight(25);
setWidth(lbl_AddCharacter.getWidth());
end;

btn_AddCharacter.init(mainForm);
with btn_AddCharacter do
begin
setParent(mainForm);
setLeft(edt_AddCharacter.getLeft() + edt_AddCharacter.getWidth() + 5);
setTop(edt_AddCharacter.getTop() + 1);
setHeight(21);
setWidth(45);
setCaption('Add');
setOnClick(handleCharacterName);
end;

btn_ShowOptions.init(mainForm);
with btn_ShowOptions do
begin
setParent(mainForm);
setLeft(mainform.getWidth() - 200);
setTop(debugbox.getTop() - 30);
setHeight(21);
setWidth(85);
setCaption('Show Options');
setOnClick(refreshOptions);
end;

btn_Save.init(mainForm);
with btn_Save do
begin
setParent(mainForm);
setLeft(mainform.getWidth() - 110);
setTop(debugbox.getTop() - 30);
setHeight(21);
setWidth(50);
setCaption('Save');
setOnClick(saveOptions);
end;

btn_Start.init(mainForm);
with btn_Start do
begin
setParent(mainForm);
setLeft(mainform.getWidth() - 55);
setTop(debugbox.getTop() - 30);
setHeight(21);
setWidth(40);
setCaption('Go');
setOnClick(refreshOptions);
end;

formWriteLn('Add a character name to get started...');
mainForm.showModal();
mainForm.free();
end;

procedure getPlayerInfo();
begin
sync(initform);
end;

var
i: Integer;

begin
getPlayerInfo();
if not ReadyToGo then
terminateScript();
{tasksInit();
WClients.init(WClients[0].Name);
setupImpBMPs();
for i to high(Players) do
with Players[i] do
addPlayer(Name, Data.Ints, Data.Strs, Data.Boos, Data.ScriptID);
repeat
for i := 0 to high(WClients) do
begin
WClients[i].switchTo();
wait(randomrange(450, 750));
WClients[i].cycle();
wait(randomrange(450, 750));
end;
until false; }
end.

EDIT: Actually it only happens if I include that first file… I don't even have to access anything from it.

Brandon

2014-08-31 15:31:30

From: Foundry
Thanks, I didn't catch that. If I need to post the include I will, I'll just need this moved up to SRL Members+.


Actually.. there's no way the first file could have compiled even by itself as mentioned in the OP (not that I doubt you or anything). But.. you have all the pointers in the file for functions wrong as far as I can tell.. And if I'm right, that would be the LEAST of your problems since the compiler/interpreter didn't even get that far down the file..

Take for example this definition:


type TIntFunc = function():Integer;
type TIntFuncArray = Array of TIntFunc;

//OR

type TIntFuncArray = array of function():Integer; //same as above.. just in one line.

Which is the only logical definition for a function pointer to your _skip function and _pray function..

which both have the signatures:

function _pray(): Integer;
function _skip(): Integer;

Now take the following function in which all the pointers aren't actually pointers but return values instead..


var
task_pray, task_forge, task_prayncast, task_fish,
task_cast, task_improve, task_mine, task_craft,
task_archery: TIntFuncArray;

procedure tasksInit();
begin
setLength(task_pray, 2);
task_pray[0] := _skip; //Will not compile. Assigning the result of calling _skip to a function pointer.
task_pray[1] := _pray; //assign the result of calling _pray to a function pointer..
setLength(task_prayncast, 3);
task_prayncast[0] := _skip;
task_prayncast[1] := _castIfCan;
task_prayncast[2] := _pray;
setLength(task_cast, 2);
task_cast[0] := _skip;
task_cast[1] := _castIfCan;
setLength(task_craft, 3);
task_craft[0] := _skip;
task_craft[1] := _craft;
task_craft[2] := _getStuff;
setLength(task_fish, 5);
task_fish[0] := _skip;
task_fish[1] := _checkRod;
task_fish[2] := _dropFish;
task_fish[3] := _fish;
task_fish[4] := _waitForFish;
setLength(task_forge, 7);
task_forge[0] := _skip;
task_forge[1] := _waitForCool;
task_forge[2] := _waitForHeat;
task_forge[3] := _smith;
task_forge[4] := _getMetal;
task_forge[5] := _heatMetal;
task_forge[6] := _coolProduct;
setLength(task_mine, 2);
task_mine[0] := _skip;
task_mine[1] := _mine;
setLength(task_archery, 2);
task_archery[0] := _skip;
task_archery[1] := _shoot;
end;


You're not actually storing a pointer to the function in the array.. what you're doing is "calling" the functions and storing the returned values in the array and since that is illegal due to int->pointer conversion not being implicit, voila.. compile time error..

So how exactly did you get these to compile at all? Again, I'm not doubting you but there's no way that could have compiled. Not even in PascalScript and certainly not in Lape. Unless you have a different definition somehow..

You'd have gotten: Error: Can't assign "Int32" to "function():Int32" at line XX in Lape and [Error] (XX:XX): Type mismatch at line XX in PascalScript..


It'd have to look like:

procedure tasksInit();
begin
setLength(task_pray, 2);
task_pray[0] := @_skip; //Will assign address of _skip to the array.
task_pray[1] := @_pray;
setLength(task_prayncast, 3);
task_prayncast[0] := @_skip;
task_prayncast[1] := @_castIfCan;
task_prayncast[2] := @_pray;
setLength(task_cast, 2);
task_cast[0] := _skip;
task_cast[1] := _castIfCan;
setLength(task_craft, 3);
task_craft[0] := @_skip;
task_craft[1] := @_craft;
task_craft[2] := @_getStuff;
setLength(task_fish, 5);
task_fish[0] := @_skip;
task_fish[1] := @_checkRod;
task_fish[2] := @_dropFish;
task_fish[3] := @_fish;
task_fish[4] := @_waitForFish;
setLength(task_forge, 7);
task_forge[0] := @_skip;
task_forge[1] := @_waitForCool;
task_forge[2] := @_waitForHeat;
task_forge[3] := @_smith;
task_forge[4] := @_getMetal;
task_forge[5] := @_heatMetal;
task_forge[6] := @_coolProduct;
setLength(task_mine, 2);
task_mine[0] := @_skip;
task_mine[1] := @_mine;
setLength(task_archery, 2);
task_archery[0] := @_skip;
task_archery[1] := @_shoot;
end;


This assumes that everything else in the file is correct and that the TIntFuncArray is defined as done above..

Olly

2014-08-31 15:42:30

From: Brandon
…


Or in one of this include files he has auto invoke turned off, and never turned back on.
OR if Brandon is right this is another way to do it:


procedure tasksInit();
begin
{$f-}
setLength(task_pray, 2);
task_pray[0] := _skip;
task_pray[1] := _pray;
setLength(task_prayncast, 3);
task_prayncast[0] := _skip;
task_prayncast[1] := _castIfCan;
task_prayncast[2] := _pray;
setLength(task_cast, 2);
task_cast[0] := _skip;
task_cast[1] := _castIfCan;
setLength(task_craft, 3);
task_craft[0] := _skip;
task_craft[1] := _craft;
task_craft[2] := _getStuff;
setLength(task_fish, 5);
task_fish[0] := _skip;
task_fish[1] := _checkRod;
task_fish[2] := _dropFish;
task_fish[3] := _fish;
task_fish[4] := _waitForFish;
setLength(task_forge, 7);
task_forge[0] := _skip;
task_forge[1] := _waitForCool;
task_forge[2] := _waitForHeat;
task_forge[3] := _smith;
task_forge[4] := _getMetal;
task_forge[5] := _heatMetal;
task_forge[6] := _coolProduct;
setLength(task_mine, 2);
task_mine[0] := _skip;
task_mine[1] := _mine;
setLength(task_archery, 2);
task_archery[0] := _skip;
task_archery[1] := _shoot;
{$f+}
end;

Brandon

2014-08-31 15:44:19

From: Olly
Or in one of this include files he has auto invoke turned off, and never turned back on.
OR if Brandon is right this is another way to do it:


procedure tasksInit();
begin
{$f-}
//..
{$f+}
end;


Well.. If that's turned off, it's going to be impossible to "guess" what else is turned off and narrow down other/further errors (Like what could possibly be causing an error on line 1 that requires a var). It's going to be hard. OP needs a more detailed post then.

I'd personally prefer to give OP the benefit of the doubt and wait and see what their definition of the code/signatures are.

Foundry

2014-08-31 16:11:36

Can a mod move this to SRL Members? I want to post the whole include.

@Brandon; Yes, I have auto invoke turned off. I have been using the first file I posted to bot for the last month so I am fairly certain it is nothing wrong with the include. I am looking right now to see if I have any variables named the same…

masterBB

2014-08-31 18:03:24

done

Foundry

2014-08-31 19:38:17

[ATTACH]23944[/ATTACH]

That's all of the include files. I tested it and it should compile.

Brandon

2014-09-01 21:12:00

I could not reproduce the problems you are having with "error on line 1".

What I did do was make it easier for you to use plugins.. Seeing as you are using the OpenGL plugin for your wurm include, I noticed that you had to combine a bunch of plugins together just to get it to target a specific process without you having to manually input the PID.. You iterated through each process and got its window handle and pid, etc.. Pretty painful.

For that reason, I updated the OpenGL plugins as well so they are now on even ground with the Direct-X ones.. They can now map memory by WindowHandle instead.. Shown here: https://github.com/Brandon-T/GLX-Colour/blob/GLX/src/Exports.c

How?


var
W, H: Integer;
Bmp: TGraphics;
begin
if (GLXSetup(GetNativeWindow())) then //like this..
begin
GetClientDimensions(W, H);
Bmp.Create(W, H, GLXImagePointer);
Bmp.Show();
Bmp.Free();
end;
end.


What it means? It means that you can just drag and drop Simba's crosshairs to whatever window you want, and it'll be able to capture colours as shown in the above code (Requires the LATEST Simba for "GetNativeWindow()").

Similarly, you can draw on external windows as usual (could already be done with the old plugins).

With the new ones I did it like:


var
W, H: Integer;
Bmp: TGraphics;
begin
if (GLXSetup(GetNativeWindow())) then
begin
GetClientDimensions(W, H);
Bmp.Create(W, H, GLXDebugPointer);
Bmp.DrawBox(0, 0, 100, 100, clRed, true); //draw a box(0, 0, 100, 100) with RED colour and fill it.
Bmp.Free();

Sleep(1000);
GLXClearDebug(); //OR Bmp.Draw(0, 0, 100, 100, clBlack, true); //to clear a specified area.
end;
end.


Those changes should ease your pain using plugins (OpenGL & Direct-X) with the browser and other windows other than SMART.. The direct-x plugins had these updates a couple days/weeks ago. (I think.. unless I forgot to push it..)


Again, I could not replicate the errors in your include. In fact, everything compiled and ran just fine. I use Simba (r1100).

Happy botting.. Maybe someone else can replicate the errors you're having.

Foundry

2014-09-02 11:52:46

@Brandon; Thank you for replying and updating the OpenGL plugin. It never occurred to me to update Simba and after doing that and removing a few things, everything compiles fine and that error at line 1 is gone. I guess it had something to do with r1004?

Anyways, it's great to finally see this again:
Compiled successfully in 3703 ms.