niektb Posted April 17, 2016 Report Share Posted April 17, 2016 @JuKu96: because of the new forum software Quote Link to comment Share on other sites More sharing options...
JuKu96 Posted April 17, 2016 Author Report Share Posted April 17, 2016 Just now, niektb said: @JuKu96: because of the new forum software Is this an known problem and will be fixed or an feature? Quote Link to comment Share on other sites More sharing options...
niektb Posted April 17, 2016 Report Share Posted April 17, 2016 You just need to edit it, and put those linebreaks back in AFAIK Quote Link to comment Share on other sites More sharing options...
JuKu96 Posted October 19, 2017 Author Report Share Posted October 19, 2017 (edited) @niektb I have re-formated the code now. Thanks for help! Edited October 19, 2017 by JuKu96 Quote Link to comment Share on other sites More sharing options...
Grugnas Posted October 24, 2017 Report Share Posted October 24, 2017 I am not very familiar with AI code. does AI support upgrades research? Quote Link to comment Share on other sites More sharing options...
Grugnas Posted October 24, 2017 Report Share Posted October 24, 2017 (edited) should i use the name of the mod as module parameter? I tried to use the bot name in caplocks but i keep having the error: "failed to create AI Player simulation/ai/imabot/data.json: can't find the module that should contain the constructor "IMABOT" " EDIT: i really don't know how, but i fixed it. Edited October 24, 2017 by Grugnas Quote Link to comment Share on other sites More sharing options...
coworotel Posted June 29, 2018 Report Share Posted June 29, 2018 Hey @JuKu96, are you still working on your AI? Maybe I could use some help. Quote Link to comment Share on other sites More sharing options...
coworotel Posted June 29, 2018 Report Share Posted June 29, 2018 (edited) So far I managed to do this, but I'm struggling to find why this.events is always undefined... Engine.IncludeModule("common-api"); var PEDRA = (function(){ var m = {}; // Constructor of PedraBot (first function to be called by Pyrogenesis) m.PedraBot = function PedraBot(settings) { API3.warn("Pedrabot: initializing..."); API3.BaseAI.call(this, settings); }; m.Pedrabot.prototype = new API3.BaseAI(); m.Pedrabot.prototype.OnUpdate = function(sharedScript) { API3.warn("Pedrabot: " + this.events.length + " events."); let time = this.gameState.getTimeElapsed()/1000; API3.warn("Pedrabot: elapsed time: " + time + "s"); for(let i in this.events) { // Why this.events is always undefined? API3.warn("Pedrabot: " + this.events[i].entity.templateName); } }; return m; }()); The warnings show but it appears undefined instead of the length of this.events. Edited June 29, 2018 by coworotel Quote Link to comment Share on other sites More sharing options...
coworotel Posted July 7, 2018 Report Share Posted July 7, 2018 (edited) The line m.PedraBot.prototype = new API3.BaseAI(); makes PedraBot inherit from BaseAI (I guess?). I've found in baseAI.js (part of the common-api): m.BaseAI.prototype.HandleMessage = function(state, playerID, sharedAI) { PlayerID = playerID; this.events = sharedAI.events; So this.events in pedraBot is the same as this.events in BaseAI. Now, when is HandleMessage called on BaseAI? I don't know. There's no call to it in Petra as well. sharedAI.events is defined in shared.js (part of common-api): /** * General update of the shared script, before each AI's update * applies entity deltas, and each gamestate. */ m.SharedScript.prototype.onUpdate = function(state) { if (this.isDeserialized) { this.init(state, true); this.isDeserialized = false; } // deals with updating based on create and destroy messages. this.ApplyEntitiesDelta(state); this.ApplyTemplatesDelta(state); Engine.ProfileStart("onUpdate"); // those are dynamic and need to be reset as the "state" object moves in memory. this.events = state.events; Now when is onUpdate called on sharedAI? No idea... Every turn maybe (by the engine)? Is BaseAI.Init also called by the engine upon beginning of the game? I'm also assuming that sharedAI is an object of "class" SharedScript, which is initialized through method SharedScript.Init, called by the engine. Not sure though... I'm a bit lost in this. It doesn't help that I'm not skilled in javascript... Would greatly appreciate any help. Edited July 7, 2018 by coworotel Quote Link to comment Share on other sites More sharing options...
Guest Posted July 7, 2018 Report Share Posted July 7, 2018 WARNING: ({Create:[{entity:1093}, {entity:1094}, {entity:1095}, {entity:1096}, {entity:1097}], Destroy:[], Attacked:[], ConstructionFinished:[], DiplomacyChanged:[], TrainingStarted:[], TrainingFinished:[], AIMetadata:[], PlayerDefeated:[], EntityRenamed:[], OwnershipChanged:[], Garrison:[], UnGarrison:[], TerritoriesChanged:[{}], TerritoryDecayChanged:[], TributeExchanged:[], AttackRequest:[], CeasefireEnded:[], DiplomacyRequest:[], TributeRequest:[]}) Thats what this.events looked like for me. So, I guess this.events[i].entity.templateName would be undefined. Could you instead change that line to: warn(uneval(this.events)); and see what happens. Unfortunately, I do not know more than that. Not really familiar with AI code. Quote Link to comment Share on other sites More sharing options...
coworotel Posted July 8, 2018 Report Share Posted July 8, 2018 13 hours ago, (-_-) said: Could you instead change that line to: warn(uneval(this.events)); and see what happens. That worked (0 A.D. dies if I put this in onUpdate btw). So in fact it's not this.events that was undefined... Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.