HELP! Need help with LUA SpawnEnemy function

Hi there, I am a beginner with LUA (used it 4 years ago but have forgotten everything), and really need some help with this exercise/scenario that I’m trying to work through. I am absolutely stuck on it.

Can anyone out there help me?

If you were told that a function ‘SpawnEnemy’ took two inputs, the first is a table to spawn at (the table should have an x,y and z component) and the second argument was a string describing the type ‘small’, “medium” or “large”. Write a function that takes four parameters:

  1. A starting position table.
  2. An offset position table.
  3. How many enemies to spawn?
  4. Type of enemy to spawn?

An example call to the function may look something like this:
Local vStart = {x = 0, y =0, z = 0}
Local vSoffset = {x = 10, y = 0, z = 0}
SpawnEnemy(vStart, vOffset, 5, “large”}

Thanks in advance!

Well first off, you wouldn’t use a table - not directly at least, you would use a Vector object
function SpawnEnemy(vStart,vOffset,size)

Thats what your function outline is gonna look like.
Before you call it you need to setup your variables (like what you have above)

local vStart = Vector(0,0,0)
local vOffset = Vector(0,0,0)[/lua]

The arguments when creating a Vector object are X,Y, and Z, respectively, so you’re on the right track with your table there.

As for the size, what exactly are you wanting to do with it?

Variables in Lua are dynamic - meaning they change types based on what’s in them

You can feed “large” directly into the function call, if that’s what you’re aiming to do.