HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Gamecache and AI

12-31-2008, 02:06 AM#1
Archmage Owenalacaster
I've been experimenting with the game's AI recently, and I wonder if it is already common knowledge that AIs can store data in a gamecache that can be retrieved by your triggers and functions and such.

Apparently triggers can also be created in AIs, but I haven't found an in-game event to which they respond.
12-31-2008, 03:01 AM#2
Here-b-Trollz
Collapse JASS:
native CommandAI takes player num, integer command, integer data returns nothing

I've never messed with AI, but I think there are Start and Pause functions as well. EDIT: It occurs to me that you were actually asking for something entirely different, and that you actually meant the handle. In that case, I actually don't know enough about AI coding to help. If you can use global variables in AI, then that helps. If you can use custom functions in AI, that SUPER helps.
12-31-2008, 03:57 AM#3
moyack
Quote:
Originally Posted by me
I just saw your thread about using game cache, but I've never tested it because I haven't had any need of it (well, we have full access to global vars anyways :P)

remember that the scope of AI is limited, the data stored in global vars is local to each player (in other words we ensure MPI). The only possible usage of gamecache in AI could be to share data between player AIs.... is what you're planning?
12-31-2008, 06:02 AM#4
Archmage Owenalacaster
I'm asking if I've discovered something new or rediscovered something.

You can use custom functions in AI.
And the natives in common.j appear to work quite well. I've spawned destructables and units. I've created units with AI, stored them in gamecache, removed them, then restored them with triggers from "in-game" (I don't know how else to refer to the map's script to differentiate it from AI).

This only seems significant to me because I thought I had read somewhere that information can be sent to an AI with CommandAI, but information cannot be retrieved from an AI. But it certainly can through gamecache.

Oh, and regarding triggers...
Hidden information:
Zoom (requires log in)


I got an AI to run a trigger with TriggerExecute after I had passed it through gamecache into an AI global.

Ingame Script
Expand JASS:
AI Script
Expand JASS:

EDIT: My next experiment is to see if I can create a blank trigger in-game and export it to AI, where event registers, conditions, and actions can be added. THAT would be fucking useful!

EDIT 2: Didn't work. Would be so nice to figure out a way around that.

It is useful, though, that an AI can execute triggers. Especially if that trigger returns information back to the AI through either CommandAI or gamecache.
12-31-2008, 12:51 PM#5
Here-b-Trollz
That's very cool.
12-31-2008, 09:12 PM#6
Archmage Owenalacaster
I expect TriggerEvaluate also works, and I know IsTriggerEnabled works. More testing remains to be done, but I've not yet found a common.j native that crashes an AI thread.

I wonder if I can make a function in AI, use Code2I to send it through the gamecache, and give it to TriggerAddAction in-game. I'd prefer to find some way of using triggers in AI, not just from it.

EDIT: Didn't work. Not surprising, but unfortunate.
01-01-2009, 08:11 AM#7
Jazradel
That's very interesting. I can't remember hearing of anyone doing this before, but it seems likely they would have back when people realised the potential of H2I + Gamecache.
01-01-2009, 11:53 AM#8
Archmage Owenalacaster
I think there is a way to use triggers to manipulate variables in an AI using handles. Using gamecache, you would pass on the AI handle to the function for a trigger action. So it seems possible, though limited and impractical. Which is to say this method would be vastly less efficient than using in-game script to accomplish the same purpose.

It is challenging to think of practical applications for this "discovery". But I'll make an attempt.

Imagine an AI player that is heavily fortified, with anti-air defenses and completely walled-in save for a few invulnerable gates. When it initiates an assault, the AI calls ExecuteTrigger(OpenGates) to allow its units out. Immediately before this, the assault units are added to a group (in-game or in AI, though I haven't tested the functionality of groups in AI). When all the units in the group have exited the Region of the base, the gates close. I can still imagine perhaps more efficient means of doing this with only in-game script, though.

Hahhah, I now frequently find myself wishing vJASS extended to AI. It would be incredibly helpful if NewGen WE supported something for AI scripting.
12-07-2009, 04:11 PM#9
leric
Quote:
Originally Posted by Archmage Owenalacaster
It is useful, though, that an AI can execute triggers. Especially if that trigger returns information back to the AI through either CommandAI or gamecache.
So can trigger run successfully in the AI?