[info] Перевод на русский от rebelka: http://rawr.su/topic/2580-kak-obedinit-stcenarii-how-to-merge-scripts/?p=8303[/info]
1. Basics
Code:
var number1,number2: integer;
begin
print('Im script 1. lets print some numbers:');
print(number1);
print(number2);
end.
Code:
var
string1,string2: string;
begin
print('Im script 2. lets print some strings:');
print(string1);
print(string2);
end.
scripts are basic, so you shouldn't have problems with locating VAR block and main body xD
2. Changing script into procedure
Code:
procedure Name;
before VAR word if present or BEGIN if not. You are free to give your procedures any name you want, but its good to use names which describe functionality of script/procedure (for better code readability).
Then we need to change END. of main script body to END;
Applying above instructions to our test scripts we will end up with:
Code:
Procedure TestScript1;
var number1,number2: integer;
begin
print('Im script 1. lets print some numbers:');
print(number1);
print(number2);
end;
Code:
Procedure TestScript2;
var
string1,string2: string;
begin
print('Im script 2. lets print some strings:');
print(string1);
print(string2);
end;
3. Time for magic!
Code:
Procedure TestScript1;
var number1,number2: integer;
begin
print('Im script 1. lets print some numbers:');
print(number1);
print(number2);
end;
Procedure TestScript2;
var
string1,string2: string;
begin
print('Im script 2. lets print some strings:');
print(string1);
print(string2);
end;
begin //start of main body
Script.NewThread(@TestScript1); delay(50);
Script.NewThread(@TestScript2);
end. //end of main body
With that you can merge scrips.
Was take from internet.
1. Basics
- Every script can have VAR block to declare variables and must have main body between BEGIN and END.
- Notice, that main body got END. with dot at it end. And all other END; ends with semicolon.
- No matter what - there must be always only ONE main body, even if you would merge 10 scripts.
Code:
var number1,number2: integer;
begin
print('Im script 1. lets print some numbers:');
print(number1);
print(number2);
end.
Code:
var
string1,string2: string;
begin
print('Im script 2. lets print some strings:');
print(string1);
print(string2);
end.
scripts are basic, so you shouldn't have problems with locating VAR block and main body xD
2. Changing script into procedure
- We want our scripts to work together inside one file, that force us to make some changes inside them.
- Each of the script which we want merged need to be first changed into procedure.
- Sounds difficult? well its not
Code:
procedure Name;
before VAR word if present or BEGIN if not. You are free to give your procedures any name you want, but its good to use names which describe functionality of script/procedure (for better code readability).
Then we need to change END. of main script body to END;
Applying above instructions to our test scripts we will end up with:
Code:
Procedure TestScript1;
var number1,number2: integer;
begin
print('Im script 1. lets print some numbers:');
print(number1);
print(number2);
end;
Code:
Procedure TestScript2;
var
string1,string2: string;
begin
print('Im script 2. lets print some strings:');
print(string1);
print(string2);
end;
3. Time for magic!
- Our merged script will contain all of the procedures we prepared in step 2. + its main body where we will call them.
- Procedures are placed out of main body, separately.
- "Magic" function to call them in separately threads is: Script.NewThread(@Name);
- It takes procedure name as parameter and start it in thread immediately after execution.
- Theoretically number of simultaneous threads is limited by memory/buffers but it will most prolly crash whole bot if you will run tons of it
- Its good practice to put small delay (like 10-100) between starting of threads
- For easy scripts its sometimes better to use this method instead of threads
- Threads are running as long as called procedure is executing, however Stop button will kill all running threads.
- If poorly written procedure will stop with error inside thread it will most often dont affect other running threads (excluding case where it cause whole bot to crash xD)
Code:
Procedure TestScript1;
var number1,number2: integer;
begin
print('Im script 1. lets print some numbers:');
print(number1);
print(number2);
end;
Procedure TestScript2;
var
string1,string2: string;
begin
print('Im script 2. lets print some strings:');
print(string1);
print(string2);
end;
begin //start of main body
Script.NewThread(@TestScript1); delay(50);
Script.NewThread(@TestScript2);
end. //end of main body
With that you can merge scrips.
Was take from internet.