Help finishing my game from tutorial

war game.zip (2.5 MB)

I have attached a copy of my game i made from the war battle tutorial, I need some help with the programming. what i need help with is running the title screen(being able to click play and the game starts), next I am having trouble with factories and spawning my units, after they are spawned i don’t really know how to program AI, next i have medics that heal but i need to work on the UI health bar for the player i have an idea of what i want to do just the 5 bars and each time player is hit it’s alpha goes to 0 showing the next bar and if he walks into a medic then it will heal and go back to the previous health bar. another mechanic in my game i’m not sure how to add would be power-ups making the guy shoot multiple missiles again i need help with spawning the item and finally i want to make waves of enemies that come in and the game to tell you your score at the end then you can click play again. I have already set up everything, like the factories and grouped and masked everything all i’m really lacking is the hard programming. if anybody can help it would be cool i looked on the boards and the topic about spawning tanks was set up different then mine so it didn’t really work when i tried it in my project so i came to a wall. I’ll probably look at the documentation of coding if i can’t find any help but this is a cool community and i really want to see my baby come to life… well the tutorial i followed and then asked people for help to complete baby but my baby none the less that taught me well and will lead to new babies!

Maybe someone will pick up your code and implement the things you are asking for, but my recommendation is that you try and learn these things yourself. How else are you going to create your next game? Break this post down into multiple questions. I’ll provide some help for #1, the title screen.

How to create multiple screens and navigate between them?

You have multiple options. One would be to use an extension, for instance Monarch. Check our asset portal. It allows you to set up multiple screens and navigate between them. If you want to do it yourself I recommend this example: https://github.com/britzl/publicexamples/tree/master/examples/menu_and_game

i’ve been looking at what to do for the ai i made collision spheres and the have a message_id for trigger response but im stuck on how to make the tanks move towards my player game object. and then i added a button input for the title screen but i don’t know what command runs the actual level. also when i try to pass the score to an endscore node in my gui it throws up an error code

In my linked example project above there are three collections:

  • controller.collection
  • game.collection
  • menu.collection

The controller.collection is set as the bootstrap collection in game.project. It contains one game object with a script (controller.script) and two collection proxy components, one for the game.collection and one for the menu.collection. The controller.script will based on message passing load either the menu.collection or the game.collection. If you look at the menu.collection you see that it consists of a gui (menu.gui and menu.gui_script). The menu.gui_script detects when the user has clicked the button and sends a message to controller.script and asks it to load the game. There is nothing more to it than that.

There is also the Color Slide tutorial which for some reason isn’t among our Tutorials (ping @sicher). It goes into the details of how to add navigation to a game.

This is an example of a simple AI that will move towards a position: publicexamples/examples/simple_ai at master · britzl/publicexamples · GitHub. Perhaps it can be of some help?

2 Likes

thanks a lot man. i was looking at your example and incorporating it into my project that makes sense when you explain it, thanks a lot. starting to make a lot of sense now

1 Like

It’s available in the ”New Project” and ”From Tutorial” in the editor welcome screen. (It’s not on the site yet though)

Exactly. I think it should be there as well.

I will check that out, so i got my tanks wandering around the map i can shoot them and it scores. my title screen is set up but how do i get that to play first? after that i think i just need some random spawing from my factories and then i’ll be getting close to an actual game!

i spoke too soon the tutorial has everything i need to know about loading games

1 Like

@sicher, @britzl alright so i have created proxy groups and implemented the code and my title screen loads then when i click the button i get an error saying the message can’t post to the controller script “show_game”, the next thing i need help with is my tanks spawning i think the problem lies within the vector3 part im not sure it says something about nil and can not spawn tank. i put music in it too but the music doesn’t play im sure that is simple but i don’t know what passes a message to the music script to play sound that it is scripted to play or like what activates it i have the script and the sound object linked to a wav file. and while im making a laundry list of questions IM SORRY but is there any examples that go over raycasting?

local function random_position()
	return vmath.vector3(math.random(40, 996), math.random(40, 996), 0)
end
local function spawn_enemy()
	return factory.create("#enemy_factory", random_position())
end

local function spawn_medic(position)
	return factory.create("#medic_factory", random_position())
end
local function spawn_helicopter()
	return factory.create("#helicopter_factory", random_position())
end

local function spawn_tank(position)
	return factory.create("#tank_factory", random_position())
end
local function spawn_powerup(position)
	return factory.create("#powerup_factory", random_position())
end

function init(self)
	msg.post(".", "acquire_input_focus")
	math.randomseed(os.time())
	self.tank = {}
	self.powerup = {}
	self.medic={}
	self.helicopter={}
	self.enemy={}
	for i = 1, 10 do
		table.insert(self.tank, spawn_tank())
	end
end


function final(self)
	msg.post(".", "release_input_focus")
end
function update(self, dt)
	if messag_id==("collision_response") then 
		table.insert(self.tank, spawn_tank(vmath.vector3(random_position(40,996),random_position(40,996),0)))
		if #self.tank==0 then
			msg.post("controller:/controller","show_menu")
	end
end

this is the game script that doesn’t spawn
function on_input(self, action_id, action)

end

end

1 Like


i made a gist for anybody to help if they want to look at some of my code

What is the specific error? I take it is from the line:

msg.post("controller:/controller","show_menu")

What is the id set on the collection that holds the “controller” game object?

Knowing the specific error message would help.

Have you looked at the relevant example and documentation?

Again, have you looked at the documentation?

1 Like

Can you insert a print statement and double check that the script runs at all?

1 Like

ERROR:SCRIPT: /main/scripts/title.gui_script:12: Could not send message ‘show_game’ from ‘main:/title/title#title-screen’ to ‘controller:/controller’.
stack traceback:
[C]: in function ‘post’
/main/

i have the tanks moving around now and the game script runs without errors but it doesn’t spawn tanks still

and yes i did look at the documentation that’s how i fixed most of the code, this was the other error i got but i fixed it kind of the guy dies now if a tank runs into him as well
ERROR:SCRIPT: /main/scripts/game.script:34: attempt to get length of global ‘tank’ (a nil value)
stack traceback:
/main/scripts/game.script:34: in function </main/scripts/game.script:22>
DEBUG:SCRIPT

I don’t understand. Your code spawns tanks in the init() function of “game controller” and you say they move around so clearly they have spawned. There is no other code that spawns tanks anywhere in that gist.

sorry if i’m not explaining it proper, I just placed tanks in the scene and was putting the tank script on them to patrol

The line that spawns tanks is this one:

local id = factory.create("#tank_factory", go.get_position(), go.get_rotation())

this means that each tank is spawned at the position of the game object that contains the script. Where is that game object placed?