Hi,
How do I make an object shoot something?
super [import]uid: 54001 topic_id: 9759 reply_id: 309759[/import]
Hi,
How do I make an object shoot something?
super [import]uid: 54001 topic_id: 9759 reply_id: 309759[/import]
Please read the rules before creating multiple threads.
http://developer.anscamobile.com/forum/2011/05/05/forum-rules-and-guidelines
Shooting can be handled in many ways. If you have a fire button, spawn a bullet at the object doing the shooting and transition it to the object you’re firing at.
That should give you something to work with and modify to suit your needs.
Peach
[import]uid: 52491 topic_id: 9759 reply_id: 35602[/import]
So, how do I take a variable from another function and use it in another function?
I want to use enemy[l] in the shootE function but the debugger says attempt to index field ‘?’ (a nil value) for line 58…
code:
http://paste.org/pastebin/view/32976 [import]uid: 54001 topic_id: 9759 reply_id: 35649[/import]
your variable “l” is not defined in shootE function.
what are you trying to achieve? [import]uid: 48521 topic_id: 9759 reply_id: 35663[/import]
I would surmise from your question about using variables in other functions that you might want to read up on the lua language itself first. Passing parameters to functions and receiving return values is basic to almost every programming language. [import]uid: 8271 topic_id: 9759 reply_id: 35854[/import]
Terrific answer, sherlock! [import]uid: 54001 topic_id: 9759 reply_id: 35949[/import]
hey
I’m trying to use a variable enemy[l] from the spawnEnemies function in another function. I tried enemy = {} outside the function ( to make things global) but stuff like that didn’t work. [import]uid: 54001 topic_id: 9759 reply_id: 35950[/import]
Any ideas? [import]uid: 54001 topic_id: 9759 reply_id: 35951[/import]
l isn’t defined in the ShootE function so enemy[l] is undefined at that point. It’s only defined in the spawnEnemies scope. [import]uid: 19383 topic_id: 9759 reply_id: 35957[/import]
Carry on, Watson… [import]uid: 8271 topic_id: 9759 reply_id: 36075[/import]
How should that look like?? I tried some things already but got nothing. [import]uid: 54001 topic_id: 9759 reply_id: 36383[/import]
In your usage within shootE() you probably want
ebullet[n].x = enemy[l].x
ebullet[n].y = enemy[l].y
to be
ebullet[n].x = enemy[n].x
ebullet[n].y = enemy[n].y
I’m assuming you want bullet 1 mapped to Enemy 1, etc.
Also, you can save a lot of pain when reviewing code or asking others by not using variables that look like numbers. There are about 24 better choices than “l” or “o” to use as your iterator variables. Just saying. 
Good luck [import]uid: 48203 topic_id: 9759 reply_id: 36398[/import]
That works. So how do I get the enemy to shoot multiple bullets? Right now, every enemy that spawns, shoots one bullet for the whole game and thats it. [import]uid: 54001 topic_id: 9759 reply_id: 36848[/import]