PSP Hacks - Forums
Go Back   PSP Hacks - Forums > Tech Talk > LUA Scripting

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2007, 11:11 AM
originalfragster originalfragster is offline
PSP Newbie
 
Join Date: Nov 2006
Location: New Zealand
Posts: 49
originalfragster User Has a Beginner Reputation
Default

Firstly, I'm not asking for any code or anything. I'm just asking for a simple explaination, and possibly an example.

I have one enemy in the game at the moment, it's properties are all tied up into a function enemy()
How can I multiply this function several times? so if this is the functions code:
Code:
function gameenemy()
if enemy.y>playerbullet.y 
and playerbullet.x<enemy.x+enemy.image:width() 
and playerbullet.x>enemy.x
then enemy.x=math.random(20,460) enemy.y=math.random(10,150)
end
end
What I am trying to achieve, is that the game automatically creates an "enemy1", "enemy2", "enemy3"... possibly with a "for" statement.

What would I need to add to achieve this?

---
function gameenemy()
for i=0,5 do
if enemy[i].y>playerbullet.y
and playerbullet.x<enemy[i].x+enemy[i].image:width()
and playerbullet.x>enemy[i].x
then enemy[i].x=math.random(20,460) enemy[i].y=math.random(10,150)
end
end
---

-This is what I want to do, loop the function's code multiple times, and each enemy acts independantly of the other. Without having to create a function per enemy.
Reply With Quote
  #2  
Old 09-03-2007, 04:11 AM
originalfragster originalfragster is offline
PSP Newbie
 
Join Date: Nov 2006
Location: New Zealand
Posts: 49
originalfragster User Has a Beginner Reputation
Default

*Bump*
Reply With Quote
  #3  
Old 09-05-2007, 05:56 AM
Blade_punk's Avatar
Blade_punk Blade_punk is offline
Moderator
PSP Monk
 
Join Date: Nov 2006
Location: Candy Mountain
Posts: 2,686
Blade_punk will become famous soon enoughBlade_punk will become famous soon enough
Default

hey,
i cant really understand you but i think you want that set up as a function so you dont have to constantly retype those lines. am i right?
you could try:

Code:
function gameenemy(object)
if object.y>playerbullet.y 
and playerbullet.x<object.x+object.image:width() 
and playerbullet.x>object.x
then object.x=math.random(20,460) object.y=math.random(10,150)
end

while true do
gameenemy(enemy)
end
then replace gameenemy(enemy) with the names of the other enemies or whatever. hope that helps
__________________
The PSP Programming and Development Mega Thread
-Rock Station-
PSN: Xsjado7
Quote:
Why don't you try walking on your hands! Then you could use your feet for hi-5's and eating sandwiches. You know, all the important stuff!
Reply With Quote
  #4  
Old 09-05-2007, 09:51 PM
LordCthulu LordCthulu is offline
Senior Member
PSP Veteran
 
Join Date: Mar 2005
Posts: 1,029
LordCthulu User Has a Beginner Reputation
Default

Using the above example, you could put a for loop inside the while loop, and have the enemies in an array. So something like..

while true do
for(i=5, i<5, i++)
gameenemy(enemy[i])
end
end

I don't remember the lua for loop though, I know that ones wrong, just an example. Back to hitting on that hot chick over there ....
__________________
Member number: 3
Meat lover? Watch: http://www.chooseveg.com/animal-cruelty.asp
Reply With Quote
  #5  
Old 09-07-2007, 06:50 AM
Blade_punk's Avatar
Blade_punk Blade_punk is offline
Moderator
PSP Monk
 
Join Date: Nov 2006
Location: Candy Mountain
Posts: 2,686
Blade_punk will become famous soon enoughBlade_punk will become famous soon enough
Default

yeah that would work well LordCthulu. so try:

Code:
function gameenemy(object)
if object.y>playerbullet.y 
and playerbullet.x<object.x+object.image:width() 
and playerbullet.x>object.x
then object.x=math.random(20,460) object.y=math.random(10,150)
end

while true do
for(i=5, i<5, i++)
gameenemy(enemy[i])
end
end
__________________
The PSP Programming and Development Mega Thread
-Rock Station-
PSN: Xsjado7
Quote:
Why don't you try walking on your hands! Then you could use your feet for hi-5's and eating sandwiches. You know, all the important stuff!
Reply With Quote
  #6  
Old 09-10-2007, 11:07 PM
originalfragster originalfragster is offline
PSP Newbie
 
Join Date: Nov 2006
Location: New Zealand
Posts: 49
originalfragster User Has a Beginner Reputation
Default

I sincerely apologise for the late reply :|
Just busy atm with exams :(

Thanks though, I'll try it out afterwards,

many thanks,
originalfragster
Reply With Quote
Reply

 



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:34 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©