An AI Question...

Do you need help? Ask here!

Bug reporting belongs here: http://developer.wz2100.net/newticket
User avatar
PSWDeanCorso
Greenhorn
Posts: 9
Joined: 26 Jan 2007, 04:20
Location: Woodland, CA
Contact:

An AI Question...

Post by PSWDeanCorso »

And yes, I'm new at scripting, and I have the theory of coding down. And know what I would like to do. Currently the AI builds in a semi-random fashion. I'd like to work it towards a structured build order. But I need to figure out how to give an order... and as far as I know (and read), this should work... except for the error. I don't know, I'll keep at it ;)

script parse error:
Type mismatch for paramter 2 at line X
Token:-1, Text:')'

with;
orderDroidObj(droid, DORDER_BUILD, derrick); // someFunction(para1, para2, para3) Right?

/////////////////////////////////////////////
...also, here is an earlier attempt...
script parse error:
Type mismatch for paramter 2 at line 102
Token:-1, Text:')'

...and the code...

// check if HQ exists, if not... build one
structureBuilt(playerHQ, player);
if (false)
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // Line 102
}

But this gives me an idea... Can a group be given and order as a whole? (yes, DORDER_HELPBUILD is a droid order, I know lol) What I'd like to have done is to give a group of trucks an order to build a building (playerHQ to start). I have been attemting to use;

orderGroupObj(GROUP, order, BASEOBJ)
Give all the units in the group an order with an object

Now yes... its a droid order for a group. My problem is that I know of no other orders. Only droid orders are listed in Scriptlang. Are there Group Orders? I have already tried some different combos of that. And of course none worked. Or perhaps I'm barking up the wrong tree, lol. Any help would be... well... helpful ;)


>>> UPDATE <<<
I now use;

Code: Select all

/////////////////////////////////////////////////////////////////////
// Build and upgrade Factories <- !!! Does NOT upgrade ATM !!!
event buildAndUpgradeFactories(buildAndUpgradeFactoriesTr)
{
  if( (player == selectedPlayer) or (not myResponsibility(player)) )
  {
    setEventTrigger(buildAndUpgradeFactories, inactive);
  }
  else
  {
    tempx = (128*mapWidth);
    tempy = (128*mapHeight);

    numFactories = numStructsByTypeInArea(player, factory, baseX,baseY, tempx,tempy); // type mismatch error on 'factory'
    boolResult = structureBuilt(playerHQ, player);
    while( (boolResult == TRUE) and (numFactories < 5) ) // this should loop five times... we'll see.
    {
      buildX = baseX;
      buildY = baseY;
      boolResult2 = pickStructLocation(factory, ref buildX, ref buildY,player);
      if(boolResult2 == TRUE)
      {
        initIterateGroup(buildGroup);
        droid = iterateGroup(buildGroup);
        while(droid != NULLOBJECT)
        {
          if(droid.order == DORDER_NONE or droid.order == DORDER_RTB)
          {
            orderDroidStatsLoc(droid, DORDER_BUILD,factory, buildX,buildY);
          }
          droid = iterateGroup(buildGroup);
        }
      }
    }
  }
}
Works great! Trucks build as a group, just needs to loop 5 times...
Last edited by PSWDeanCorso on 09 Feb 2007, 23:25, edited 1 time in total.
User avatar
Watermelon
Code contributor
Code contributor
Posts: 551
Joined: 08 Oct 2006, 09:37

Re: An AI Question...

Post by Watermelon »

PSWDeanCorso wrote: And yes, I'm new at scripting, and I have the theory of coding down. And know what I would like to do. Currently the AI builds in a semi-random fashion. I'd like to work it towards a structured build order. But I need to figure out how to give an order... and as far as I know (and read), this should work... except for the error. I don't know, I'll keep at it ;)

script parse error:
Type mismatch for paramter 2 at line X
Token:-1, Text:')'

with;
orderDroidObj(droid, DORDER_BUILD, derrick); // someFunction(para1, para2, para3) Right?
I havent read the script related source files thoroughly,though I think all variables must be declared as specified type before use.In your script,'derrick' is undeclared,it should be declared as BASE_OBJECT
or script counterpart 'BASEOBJ' I think.
/////////////////////////////////////////////
...also, here is an earlier attempt...
script parse error:
Type mismatch for paramter 2 at line 102
Token:-1, Text:')'

...and the code...

// check if HQ exists, if not... build one
structureBuilt(playerHQ, player);
if (false)
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // Line 102
}

But this gives me an idea... Can a group be given and order as a whole? (yes, DORDER_HELPBUILD is a droid order, I know lol) What I'd like to have done is to give a group of trucks an order to build a building (playerHQ to start). I have been attemting to use;

orderGroupObj(GROUP, order, BASEOBJ)
Give all the units in the group an order with an object

Now yes... its a droid order for a group. My problem is that I know of no other orders. Only droid orders are listed in Scriptlang. Are there Group Orders? I have already tried some different combos of that. And of course none worked. Or perhaps I'm barking up the wrong tree, lol. Any help would be... well... helpful ;)

// check if HQ exists, if not... build one
structureBuilt(playerHQ, player);
if (false)
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // Line 102
}


should be


// check if HQ exists, if not... build one
if (!(structureBuilt(playerHQ, player)))
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // Line 102
}


since it doesnt store the result of 'structureBuilt(playerHQ, player)' in a 'stack',so 'if(false)' caused failure,cos you cannot check null against undeclared variable 'false'.

the 'Group' here is referring to the commander group not the numeric ones(Ctrl+1,Ctrl+2 etc),not sure which one is what you wanted to use though.
tasks postponed until the trunk is relatively stable again.
User avatar
PSWDeanCorso
Greenhorn
Posts: 9
Joined: 26 Jan 2007, 04:20
Location: Woodland, CA
Contact:

Re: An AI Question...

Post by PSWDeanCorso »

Watermelon wrote: the 'Group' here is referring to the commander group not the numeric ones(Ctrl+1,Ctrl+2 etc),not sure which one is what you wanted to use though.
I'll use the numeric groups... and btw, would dling the source provide further docs that define the scriptlang?
User avatar
lav_coyote25
Professional
Professional
Posts: 3434
Joined: 08 Aug 2006, 23:18

Re: An AI Question...

Post by lav_coyote25 »

already on the site here
‎"to prepare for disaster is to invite it, to not prepare for disaster is a fools choice" -me (kim-lav_coyote25-metcalfe) - it used to be attributed to unknown - but adding the last bit , it now makes sense.
User avatar
PSWDeanCorso
Greenhorn
Posts: 9
Joined: 26 Jan 2007, 04:20
Location: Woodland, CA
Contact:

Re: An AI Question...

Post by PSWDeanCorso »

lav_coyote25 wrote: already on the site here
Do you mean the scriptlang.rtf? If so... it gives me some ideas, but I seem to have trouble actually getting it to work. And editing the original AI (which is what I have been doing as of late) seems so inefficient. This is because I'll eventually re-write the entire script anyway. And like I have said, I am always trying different things out ;) Would studying the C language help? I have already looked at C++ in the past, so I know the basics.

Watermelon wrote:
// check if HQ exists, if not... build one
if (!(structureBuilt(playerHQ, player)))
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // Line 102
}

Code: Select all

if (not(structureBuilt(playerHQ,player))) // this line works fine (it didn't like '!'), also note that playerHQ is defined as a STRUCTURESTAT
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // now since thats the case... does it not fit here (where it orders a group to build an OBJ or BASEOBJ)?
}

Code: Select all

////////////////////////////////////
// I wonder if I could do this; (assuming there is a type mismatch error, which I have been getting)
public STRUCTURESTAT playerHQ;
public BASEOBJ buildPlayerHQ;

buildPlayerHQ = playerHQ; // I know this isn't correct... just not sure how as of yet
if (not(structureBuilt(playerHQ,player)))
{
  orderGroupObj(buildGroup, DORDER_HELPBUILD, buildPlayerHQ); // defined as a BASEOBJ
}
aslo, the playerHQ is also defined as;
structs[2] STRUCTURESTAT "A0CommandCentre" // Line 64, original vlo file
in the .vlo file... would this be better suited, tho it is still a STRUCTURESTAT?


>>> UPDATE <<<
See original post...
Last edited by PSWDeanCorso on 09 Feb 2007, 23:13, edited 1 time in total.
User avatar
Watermelon
Code contributor
Code contributor
Posts: 551
Joined: 08 Oct 2006, 09:37

Re: An AI Question...

Post by Watermelon »

PSWDeanCorso wrote: Do you mean the scriptlang.rtf? If so... it gives me some ideas, but I seem to have trouble actually getting it to work. And editing the original AI (which is what I have been doing as of late) seems so inefficient. This is because I'll eventually re-write the entire script anyway. And like I have said, I am always trying different things out ;) Would studying the C language help? I have already looked at C++ in the past, so I know the basics.


if (not(structureBuilt(playerHQ,player))) // this line works fine (it didn't like '!'), also note that playerHQ is defined as a STRUCTURESTAT
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // now since thats the case... does it not fit here (where it orders a group to build an OBJ or BASEOBJ)?
}

////////////////////////////////////
// I wonder if I could do this; (assuming there is a type mismatch error, which I have been getting)
public STRUCTURESTAT playerHQ;
public BASEOBJ buildPlayerHQ;

buildPlayerHQ = playerHQ; // I know this isn't correct... just not sure how as of yet
if (not(structureBuilt(playerHQ,player)))
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, buildPlayerHQ); // defined as a BASEOBJ
}

aslo, the playerHQ is also defined as;
structs[2] STRUCTURESTAT "A0CommandCentre" // Line 64, original vlo file
in the .vlo file... would this be better suited, tho it is still a STRUCTURESTAT?
sorry didnt know wz script doesnt have logical operation '!'

To answer you type conversion question:

This is from scriptlang.rtf:

NOTE: the functions objToDroid, objToStructure and objToFeature exist to convert a BASEOBJ
  to a droid, structure or feature if the base obj is of the right type.


so it should be:

public STRUCTURESTAT playerHQ;
public BASEOBJ buildPlayerHQ;
playerHQ = objToStructure(buildPlayerHQ);
tasks postponed until the trunk is relatively stable again.
Troman
Trained
Trained
Posts: 424
Joined: 12 Aug 2006, 15:40
Contact:

Re: An AI Question...

Post by Troman »

PSWDeanCorso wrote: orderDroidObj(droid, DORDER_BUILD, derrick); // someFunction(para1, para2, para3) Right?
[..]
...also, here is an earlier attempt...
script parse error:
Type mismatch for paramter 2 at line 102
Token:-1, Text:')'

...and the code...

// check if HQ exists, if not... build one
structureBuilt(playerHQ, player);
if (false)
{
orderGroupObj(buildGroup, DORDER_HELPBUILD, playerHQ); // Line 102
}
For DORDER_BUILD you should use this function :

Code: Select all

orderDroidStatsLoc(DROID, INT order, STRUCTURESTAT stats, INT x, INT y)
And for DORDER_HELPBUILD this one:

Code: Select all

orderDroidObj(DROID, order, BASEOBJ)
PSWDeanCorso wrote:But this gives me an idea... Can a group be given and order as a whole?
[..]
Now yes... its a droid order for a group. My problem is that I know of no other orders. Only droid orders are listed in Scriptlang. Are there Group Orders?
Yep, you can give orders to groups. Even though it might look confusing at first but there are no special group orders, droid orders are used for both droids and groups.
PSWDeanCorso wrote:public STRUCTURESTAT playerHQ;
public BASEOBJ buildPlayerHQ;

buildPlayerHQ = playerHQ; // I know this isn't correct... just not sure how as of yet
I'm not sure what you are trying to do, but this won't work, you can't assign STRUCTURESTAT to a STRUCTURE variable.

If what you want is to check if a certain structure on the map is completely built you first have to assign this structure to a STRUCTURE variable ('structure' in this case). For example you can make a loop to iterate through all factories of player 7:

Code: Select all

initEnumStruct(FALSE,factory,7,7); //prepare iteration through all factories of player 7 which are visible to player 7 (although checking visibility doesn't make much sense here)
structure = enumStruct();	//get first factory, will be NULLOBJECT if wz can't find any
while(structure != NULLOBJECT)		//make sure we won't try to access a NULLOBJECT
{
	if( not (structureComplete(structure)) )	//not finished building this factory
	{
		orderGroupObj(buildGr, DORDER_HELPBUILD, structure); // order all trucks to build it
	}
	structure = enumStruct();	//get next factory and repeat the whole thing
}
If you want only certain trucks to help building it, you will have to iteratte through all trucks and send them one by one.

PSWDeanCorso wrote:aslo, the playerHQ is also defined as;
structs[2] STRUCTURESTAT "A0CommandCentre" // Line 64, original vlo file
in the .vlo file... would this be better suited, tho it is still a STRUCTURESTAT?
It shouldn't really matter, those two STRUCTURESTATs are identical for the scripts, "playerHQ" is just easier to read in the script, while having HQ in structs[] array makes it easier for the scripts to iterate through all base structures.

Watermelon wrote:public STRUCTURESTAT playerHQ;
public BASEOBJ buildPlayerHQ;
playerHQ = objToStructure(buildPlayerHQ);
I guess it is a bit confusing. objToStructure() converts BASEOBJ to STRUCTURE, not to STRUCTURESTAT. The difference between STRUCTURE and STRUCTURESTAT is that STRUCTURE is a pointer to the real in-game structure, like a factory or a hardpoint that is placed on map. While STRUCTURESTAT is a pointer to the structure type.
Sign Up for Beta-Testing:
?topic=1617.0
User avatar
PSWDeanCorso
Greenhorn
Posts: 9
Joined: 26 Jan 2007, 04:20
Location: Woodland, CA
Contact:

Re: An AI Question...

Post by PSWDeanCorso »

ok, that sorts a bit out... thanks

here is where im at currently;

Code: Select all

/////////////////////////////////////////////////////////////////////
event gameStart (CALL_GAMEINIT)
{
  groupAddArea(buildGroup, player, 0, 0, (mapWidth*128), (mapHeight*128));
  initIterateGroup(buildGroup);
  droid = iterateGroup(buildGroup);
  boolResult = structureBuilt(playerHQ, player);
  if((boolResult == FALSE) and (droid != NULLOBJECT))
  {
    // two seperate attempts... one is commented out
    orderDroidStatsLoc(droid, DORDER_BUILD, playerHQ, 100, 100); // a single truck rolls over and loops around the top-left corner of the map... (im using New Team War map, me as player 0, and altered ai as player 1)
    //orderDroidObj(droid, DORDER_HELPBUILD, playerHQ); // type mismatch error on paramter 2
  }
}
in the orderDroidStatsLoc function, i have altered the x and y and the resulting effect remained the same (these where put in at random for testing)
Now... in functions are paramters numbered starting with 1 or 0?

Although, the truck does look cute driving about with no direction ;P


>>> UPDATE <<<
See original post...
Last edited by PSWDeanCorso on 09 Feb 2007, 23:17, edited 1 time in total.
User avatar
DevUrandom
Regular
Regular
Posts: 1690
Joined: 31 Jul 2006, 23:14

Re: An AI Question...

Post by DevUrandom »

groupAddArea(buildGroup, player, 0, 0, (mapWidth*128), (mapHeight*128));
Don't tell me the tile-size (pixels) is hardcoded into the scripts, too. Noooo.... (/me dies thousand deaths)
User avatar
kage
Regular
Regular
Posts: 751
Joined: 05 Dec 2006, 21:45

Re: An AI Question...

Post by kage »

i'm guessing there's a way the texture resolution of tiles can be changed without affecting the scripts, and even then, if, in a scripting lang update we add a "language version" setting, then we should be able to provide a builtin function that will return the correct "length of tile" resolution (in this case, it was 128) for the new scripts, and a compatibility layer for the older scripts that alters mapWidth and mapHeight by whatever values are necessary to allow the legacy scripts to function correctly (/dev dies only hundred deaths)
User avatar
PSWDeanCorso
Greenhorn
Posts: 9
Joined: 26 Jan 2007, 04:20
Location: Woodland, CA
Contact:

Re: An AI Question...

Post by PSWDeanCorso »

I am unclear on these two fuctions found in ScriptLang...

INT numStructsByTypeInArea(PLAYER, TYPE, X1,Y1, X2,Y2) // What are the "TYPE"s avaliable?
Return the number of structures of a certain type in an area.

INT skGetFactoryCapacity( STRUCTURE str)
Return the capacity of factory str. // factory "str."? ... meaning Structure?
User avatar
Watermelon
Code contributor
Code contributor
Posts: 551
Joined: 08 Oct 2006, 09:37

Re: An AI Question...

Post by Watermelon »

PSWDeanCorso wrote: I am unclear on these two fuctions found in ScriptLang...

INT numStructsByTypeInArea(PLAYER, TYPE, X1,Y1, X2,Y2) // What are the "TYPE"s avaliable?
Return the number of structures of a certain type in an area.

INT skGetFactoryCapacity( STRUCTURE str)
Return the capacity of factory str. // factory "str."? ... meaning Structure?
TYPE is referring to the structure types:factory,cyborg factory,research facility,power plant,headquarter I think

str is the parameter name,prolly short for 'structure',that function returns the capacity INT (0 = small 1 = medium 2 = heavy 3 = superheavy iirc)
tasks postponed until the trunk is relatively stable again.
User avatar
PSWDeanCorso
Greenhorn
Posts: 9
Joined: 26 Jan 2007, 04:20
Location: Woodland, CA
Contact:

Re: An AI Question...

Post by PSWDeanCorso »

Watermelon wrote: TYPE is referring to the structure types:factory,cyborg factory,research facility,power plant,headquarter I think

Code: Select all

trigger buildAndUpgradeFactoriesTr (wait, 150);

/////////////////////////////////////////////////////////////////////
// Build and upgrade Factories <- !!! Does NOT upgrade ATM !!!
event buildAndUpgradeFactories(buildAndUpgradeFactoriesTr)
{
  if( (player == selectedPlayer) or (not myResponsibility(player)) )
  {
    setEventTrigger(buildAndUpgradeFactories, inactive);
  }
  else
  {
    tempx = (128*mapWidth);
    tempy = (128*mapHeight);

    //count = 0;
    numFactories = numStructsByTypeInArea(player, factory, baseX,baseY, tempx,tempy); // Line 159 (commented out if using count)
    boolResult = structureBuilt(playerHQ, player);
    while( (boolResult == TRUE) and (numFactories < 5) ) // numFactories == count
    {
      buildX = baseX;
      buildY = baseY;
      boolResult2 = pickStructLocation(factory, ref buildX, ref buildY,player);
      if(boolResult2 == TRUE)
      {
        initIterateGroup(buildGroup);
        droid = iterateGroup(buildGroup);
        while(droid != NULLOBJECT)
        {
          if(droid.order == DORDER_NONE or droid.order == DORDER_RTB)
          {
            orderDroidStatsLoc(droid, DORDER_BUILD,factory, buildX,buildY);
            // count= count + 1;
          }
          droid = iterateGroup(buildGroup);
        }
      }
    }
  }
}

/////////////////////////////////////////////////////////////////////
// Result; Type mismatch for paramter 1 at line 159

// So it doesn't accept 'factory'
numFactories = numStructsByTypeInArea(player, factory, baseX,baseY, tempx,tempy);
Also, I've looked through the ScriptLang.rtf to see if another function defined "TYPE", and found nothing. Perhaps it means type of structure (BASEOBJ, STRUCTURE, among others). And those give syntax errors of course.

I've also tried the loop using count (which is commented out, if I have done the count loop wrong... let me know. As I will use that to get my desired effect). And thx Watermelon!

// Edit Kamaze: I was so free to add [ code ] tags.
Last edited by Kamaze on 08 Feb 2007, 00:56, edited 1 time in total.
Troman
Trained
Trained
Posts: 424
Joined: 12 Aug 2006, 15:40
Contact:

Re: An AI Question...

Post by Troman »

PSWDeanCorso wrote: Now... in functions are paramters numbered starting with 1 or 0?
I think it starts with 1, i'm not sure though.
PSWDeanCorso wrote: Although, the truck does look cute driving about with no direction ;P
That could be because you ordered it to build on some location it can't reach. Before giving a build order you should check if this location can be built on with

Code: Select all

BOOL pickStructLocation(STRUCTURESTAT,ref x, ref y, player);
You provide it with build coordinates and it checks if a particular structure can be built on that location, if no it tries to find a suitable spot nearby. If it fails it returns FALSE.

orderDroidStatsLoc() expects build coordinates in world units.
That means tile coordinate * 128 (there are 128 units in a tile), so your call has to look like this:

Code: Select all

orderDroidStatsLoc(droid, DORDER_BUILD, playerHQ, 100 * 128, 100 * 128);
PSWDeanCorso wrote: //orderDroidObj(droid, DORDER_HELPBUILD, playerHQ); // type mismatch error on paramter 2
If playerHQ is of type STRUCTURESTAT you can't use it as parameter in orderDroidObj(), look at the function definition:

Code: Select all

orderDroidObj(DROID, order, BASEOBJ)
it expects BASEOBJ, not STRUCTURESTAT.
DevUrandom wrote: Don't tell me the tile-size (pixels) is hardcoded into the scripts, too. Noooo.... (/me dies thousand deaths)
Replacing all occurencies of '128' with a simple function returning tile size, as suggested by Kage, or a define will do the trick.
PSWDeanCorso wrote: I am unclear on these two fuctions found in ScriptLang...

INT numStructsByTypeInArea(PLAYER, TYPE, X1,Y1, X2,Y2) // What are the "TYPE"s avaliable?
It's STRUCTURESTAT most likely.
Sign Up for Beta-Testing:
?topic=1617.0
User avatar
PSWDeanCorso
Greenhorn
Posts: 9
Joined: 26 Jan 2007, 04:20
Location: Woodland, CA
Contact:

Re: An AI Question...

Post by PSWDeanCorso »

Sorry bout the confusion... my last post (before this one) is a kind of update... no more cute trucks. And thanks Kamaze, I wasn't aware of that tag.

Now for...
INT numStructsByTypeInArea(PLAYER, TYPE, X1,Y1, X2,Y2) // What are the "TYPE"s avaliable?

I have tried 'factory' which is defined in the stock .vlo as a STRUCTURESTAT;

factory STRUCTURESTAT "A0LightFactory"

And it gave the type mismatch error.


Also, for the numbering of paramters;

numFactories = numStructsByTypeInArea(factory, factory, baseX,baseY, tempx,tempy); // Line 159
Gives;

script parse error:
Type mismatch for paramter 0 at line 159 // gave another for para 1
Token: -1, Text:')'

Script player1.slo did not compile

This event init once and should loop 5 times and stop, as far as I know my while/count loop should to the trick, but is not... it builds one factory only (this loop is in my last post, commented out)

>>> UPDATE <<<
See original post...
Last edited by PSWDeanCorso on 09 Feb 2007, 23:26, edited 1 time in total.
Post Reply