Rules js Modification

For AI and campaign script related discussions and questions
Post Reply
User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 371
Joined: 15 Apr 2018, 17:25
Location: United States.

Rules js Modification

Post by WZ2100ModsFAn »

I was modifying the rules to use const instead of the seperate enablestructures

here it is

Code: Select all

		const START_STRUCTURES = [
			"A0CommandCentre",
			"A0LightFactory",
			"A0ResourceExtractor",
			"A0PowerGenerator",
			"A0ResearchFacility",
		];

		enableStructure(START_STRUCTURES, playnum);		// make structures available to build
is there a mistake i made in the const part?

seperate one i also made

Code: Select all

		const RESEARCH_START = [
			"R-Sys-Sensor-Turret01",
			"R-Wpn-MG1Mk1",
			"R-Sys-Engineering01",
		];

		enableResearch(RESEARCH_START, playnum);		// enable clean tech research
User avatar
Berserk Cyborg
Code contributor
Code contributor
Posts: 938
Joined: 26 Sep 2016, 19:56

Re: Rules js Modification

Post by Berserk Cyborg »

What you want is to access each element of that array and pass it to enableStructure(). This can be done in a for loop by making use of the length property of an array, which returns how many elements are in that array.

Code: Select all

for (var i = 0; i < START_STRUCTURES.length; ++i)
{
    var stat = START_STRUCTURES[i];
    enableStructure(stat, player);
}
Alternatively, you could make use of the forEach method for such a simple task:

Code: Select all

START_STRUCTURES.forEach(function(stat) { enableStructure(stat, player); });
User avatar
WZ2100ModsFAn
Trained
Trained
Posts: 371
Joined: 15 Apr 2018, 17:25
Location: United States.

Re: Rules js Modification

Post by WZ2100ModsFAn »

I chose the top one.

Now to try it out.

I double posted again *facepalm* :oops:

and it this time it happened when i simply just hit submit once.

Edit:

Now i realize the top one replacing it didn't work.

hmm perhaps i made a mistake? checking to find out.

now it finally doesn't work.

here's the logs.

Code: Select all

--- Starting log [C:\Users\WZ2100ModsFan\Desktop\Warzone 2100 Portable-master\Warzone 2100 master\logs\WZlog-0902_074620.txt]---
error   |07:46:29: [callFunction:243] 0 : eventGameInit() at multiplay/skirmish/rules.js:209
error   |07:46:29: [callFunction:243] 1 : <global>() at -1
info    |07:46:29: [callFunction:246] Uncaught exception calling function "eventGameInit" at line 209: ReferenceError: Can't find variable: player
info    |07:46:29: [callFunction:246] Assert in Warzone: c:\projects\warzone2100\src\qtscript.cpp:246 (false), last script event: '<none>'
nope apparently not. fixing player with playnum.

now it works flawlessly now to start playing 8)
Post Reply