NEW WAYS OF SCRIPTING

Daxter_06

New member
Joined
May 9, 2006
Messages
458
New Ways of Scripting

Hey everyone. I will be using this thread to show you new pieces of code that
will allow you to further improve your scripting and give you the ability
to use these new pieces to make scripting easier.

An example of this is new variable scripting methods. The first method
allows you to make a variable equal to more than one thing without using
another line.

Variable = expression + expression

e.g.

oTown = get town with id 0
nPlayer = get oTown player
MeleePlatoons = variable constant from ARMY_UNIT_TYPE_MELEE_1 to ARMY_UNIT_TYPE_MELEE_10
Gatehouse = get building ABODE_NUMBER_GATEHOUSE in oTown min built 1.0

oPlatoon = get platoon of player nPlayer nearest {Gatehouse} radius 50.0 + get platoon of type constant MeleePlatoons nearest {Gatehouse} radius 50.0

This method of looking for a platoon will check to see if any platoons of the specific player of
any level from Melee 1 to Melee 10 (in this case but you can do the same for ranged platoons) are near the gatehouse. "MeleePlatoons" declares that any platoon of level 1-10 can be any platoon and if that platoon is of the specified player then it exists and is near the gatehouse. In this case the gate will open.

The line equal to oPlatoon which says "get platoon of type constant MeleePlatoons nearest {Gatehouse} radius 50.0" looks for any platoons between Melee levels 1-10 by saying that the variable "MeleePlatoons" holds the value of constants Melee type 1 to Melee type 10 and therefore platoons of any of those levels is a valid platoon.

In simplified terms of the above variable;

oPlatoon = look for a platoon of any player of any level between the min and max set

e.g.

oPlatoon = player 0 + Melee level 2  which therefore is a valid platoon.

Use of this variable declaration method is used in my AI script(s).
 
That is an interesting way of doing thngs.. :yes

I'm just curious  about something.

Code:
oPlatoon = get platoon of player nPlayer nearest {Gatehouse} radius 50.0 + get platoon of type constant MeleePlatoons nearest {Gatehouse} radius 50.0

The first part would find the closest platoon belonging to nPlayer, but the wouldn't the second part look for the closest platoon belonging to any player? ???
 
Kays said:
That is an interesting way of doing thngs.. :yes

I'm just curious  about something.

Code:
oPlatoon = get platoon of player nPlayer nearest {Gatehouse} radius 50.0 + get platoon of type constant MeleePlatoons nearest {Gatehouse} radius 50.0

The first part would find the closest platoon belonging to nPlayer, but the wouldn't the second part look for the closest platoon belonging to any player? ???

Code:
This method of looking for a platoon will check to see if any platoons of the specific player of
any level from Melee 1 to Melee 10 (in this case but you can do the same for ranged platoons) are near the gatehouse

What i have said here about looking for certain platoons is still true however,

Code:
oPlatoon = get platoon of player nPlayer nearest {Gatehouse} radius 50.0 + get platoon of type constant MeleePlatoons nearest {Gatehouse} radius 50.0

Had a bug in it and so I have changed so that the script looks for the platoon of the specific player + also look for the level of the platoon between 1 and 10 of the specific player. Exploring that I have deducted this way is much more cleaner and simple and workable:

Code:
oPlatoon = get platoon of player nPlayer nearest {Gatehouse} radius 50.0
oPlatoon += get platoon of type constant MeleePlatoons nearest {Gatehouse} radius 50.0

But please don't ask why this because I still am not a MasterPro at scripting but I do know that this does work.

I have tried:

Code:
oPlatoon = get platoon of type constant MeleePlatoons of player nPlayer nearest {Gatehouse} radius 50.0

BUT, it gives an error saying "error: "MeleePlatoons" is not a constant". So I won't go there.  :)

Btw I'm gonna PM you something about the Slib. Catch it.
 
That is interesting. I can see where += would work since the platoon's player has already been defined
 
Yep. Btw, if you have any new ways that you have thought of, then by all means post it. I and other scripters (if there are any) are always looking for faster and better ways to script.  :)
 
I can't call this new methods, but it is something basic which might help some people.

A bit about Variables, Constants, Globals and Arrays

Variables

A variable is the token you use to refer to something in the script. A variable is identified by the fact that it contains both upper and lower case characters. Numbers can also be included.

An example of a variable is "oTown". What you call your variables is up to you. One convention used by some scripters is to prefix an object with an "o" as on "oTown', "v" for visuals, "e" for epics etc, etc.

The following will identify your town as oTown

Code:
oTown = get player 0 town

Note: Variables must be defined at the beginning of the script and it can only be used in that script.

Globals

Globals are variables which can be used in all running scripts. Global must be defined first before running any any scripts.

Code:
global oTown = get town with id 0

Constants

A constant is similar to a global in that it's value can be used in all running scripts. However, it's value is fixed. A constant is identified by the fact that it all in upper case. Now, constants must be defined first before anything.

Code:
define NUMBER_OF_TOWNS = 13

Arrays
(arrays are fun)

An array is simply a variable with holds more than one value. An array is identified by the square brackets after the variable name. The contents of the brackets is a number which identifies the element (starting at 0) or a variable or constant. When defining an array, you must show the number of elements it contains.

Code:
global Town[NUMBER_OF_TOWNS]

If NUMBER_OF_TOWNS is 13, the results will be the same as:

Code:
global Town[13]

So, what can an array do for you? For a start if you have a number of similar items, such as towns or locations, you don't need to define them all. Secondly, you can use an array to loop through them to perform a check or something similar.

The following example will loop through the towns and award tribute for each one belonging to player 0 (you).

Code:
begin script checkTowns

	Town[NUMBER_OF_TOWNS] // NUMBER_OF_TOWNS is previously defined
	Cnt = 0 // a temporary variable
start
	force while Cnt < NUMBER_OF_TOWNS
		Town[Cnt] = get town with id Cnt
		if get Town[Cnt] player == 0
			increment tribute by 100000		
		end if
		Cnt++  //increment Cnt
	end while
	
end script checkTowns
 
Back
Top