Author Topic: Annikk's Mechanics  (Read 10568 times)

0 Members and 1 Guest are viewing this topic.

Lost Seedling

  • Shrub
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 148
Re: Annikk's Mechanics
« Reply #30 on: July 08, 2011, 12:10:47 PM »
I am trying to incorporate the AI engine into my map. I followed your implementation instructions as far as I can tell but on starting the map I get an error code "attempt to call global 'AIinit' (a nil value)" in the LevelSetup() section. I haven't been able to find another map that follows your instructions for comparison. Any ideas as to the problem?

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #31 on: July 08, 2011, 02:04:56 PM »
It's common that either you don't have the () or that you haven't implented the function or that the function runner is written wrong.

This should be added to common error messages Topic, when made :)

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Annikk's Mechanics
« Reply #32 on: July 08, 2011, 02:33:00 PM »
Yeah sounds to me as if you've forgotten the brackets. Also did you see the Before and After level files I attached to the post?

Lost Seedling

  • Shrub
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 3
  • Posts: 148
Re: Annikk's Mechanics
« Reply #33 on: July 08, 2011, 10:34:19 PM »
Working now. Thanks! The problem was not my typing but that I didn't get the initialization function from the original file, so there was no init function to call at the init command. 

 

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #34 on: July 09, 2011, 08:57:50 AM »
Annikk, could the AI be split into it's own file, with only a few function calls in the map? It might make it easier to incorporate, and you wanted to condense it a bit.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #35 on: July 09, 2011, 12:59:22 PM »
Pilchard, that should work if you can map the whole AI from the file to the map :)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #36 on: July 09, 2011, 03:04:07 PM »
Yeah, not too hard.

Add dofile(path to Infected AI Engine file) as the first line of your LevelSetup(). You can then call any functions from Infected AI Engine.lua in your level with impunity. The path section may/will need updating, depending on where you save the AI, but that is all.

And example level may say:
function LevelSetup()
    dofile("C:/Infected AI Engine.lua")
    {[add roids here]}
    AIinit()
end
function LevelLogic()
    {[blahblahblahblah]}
    InfectedAIEngine()
end


It's a lot simpler to look at, you know from the code it uses IAI and you don't need to copy the engine across. It could do with a little tweaking to prevent problems like the filepath being incorrect, but that can be fixed by changing the path...

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #37 on: July 09, 2011, 03:44:26 PM »
you can use dofile?? Dx

Thanks Pilchard, you now just let my pressure on the Adveture code by 10000 times :D

Now I can load codes externaly, like loading maps externaly I guess :D

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #38 on: July 09, 2011, 03:49:11 PM »
Wait, so I can store dofile(path) as a var and then run everything in it? It doesn't run when you do the dofile code??

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 899
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #39 on: July 09, 2011, 03:56:33 PM »
It runs when you call dofile(path). However, since the only thing in IAI.lua is function definitions nothing really happens. The functions are defined and stored as if they were declared in the same file as the level.

However, the code in path is all compiled each time dofile(path) is run. To use external functions more than one, use loadfile(path).
function foo = loadfile(path) This will compile only once, and save the contained code as the function foo.

Read this for a better explanation: http://www.lua.org/pil/8.html

kmercy

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
Re: Annikk's Mechanics
« Reply #40 on: July 09, 2011, 05:14:10 PM »
Yes yes i know im back

This is what i use if i want to take seedlings from one map to the next really simple actually check it for yourself:
Code: [Select]
-- kmercy Reinforcements code V1
rein = GetEmpire(1).NumSeedlings / 10
os.execute("mkdir " .. "C:\\Rein\\")
io.output(io.open("C:\\Rein\\" .. "Rein","w"))
meh = "-- Reinforcements v1\n\n"
meh = meh .. "\tReinforcements = " .. rein .. "\n\n"
meh = meh .. "-- Reinforcements v1 END"
io.write(meh)
io.close()
-- kmercy Reinforcements code V1 END

can be used in other maps like so:
dofile("C:/Rein/Rein")
a:AddSeedlings(Reinforcements)

Remember there was discussion about reinforcements so got me thinking ;p
« Last Edit: July 09, 2011, 05:20:36 PM by kmercy »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #41 on: July 09, 2011, 05:19:41 PM »
I've fixed that ages ago, but not in the same way as you have :P

I didn't know of dofile, so I did it so much more complicated D:

kmercy

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
Re: Annikk's Mechanics
« Reply #42 on: July 09, 2011, 05:21:34 PM »
Didn't know you needed it but anyway its just there for anyone wanting to know how to do anything like that or exactly that :P

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 20
  • Posts: 1,483
  • They'll eat you next!
  • Eufloria: Yes
Re: Annikk's Mechanics
« Reply #43 on: July 09, 2011, 05:38:31 PM »
You gave me the information I needed for simplifying, yet making my map harder to install xD

kmercy

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 34
Re: Annikk's Mechanics
« Reply #44 on: July 09, 2011, 08:34:25 PM »
well enjoy haha :P