Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / gosub used by multiple enemies?

Author
Message
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 16th Apr 2009 05:04
hi i havent been able to figure out how to make more than 1 enemy use my enemys gosub.
the gosub moves the enemy to the player,attacks then moves away.

if i use a for next loop it makes all the enemies do exactly the same thing like all of them move or attack.

my gosub looks like..

if enemystate=0

attack

if (end of attack) then enemystate=10

if enemystate=10

move away

if so far,then enemystate=20

endif

if enemystate=20 then move to player again.

i cant figure out how to make the states reusable by multiple enemies. can anyone help?? or explain how better to write my code??? so i can use the same gosub for multiple enemies????
kuljot
15
Years of Service
User Offline
Joined: 2nd Jan 2009
Location: sacramneto, ca united states
Posted: 16th Apr 2009 05:28 Edited at: 16th Apr 2009 05:31
instead of using gosub make a function. basically you go

[b]function[/b] name here()
here right the code to control enemies
endfunction

to call function
name of function()


functions can be used over and over. when makign function or callign it put this right next to the name (). the paranthesese.

Gateway GT5628 Quad Core Desktop Intel Core 2 Q6600 2.4GHz Quad Core 3072MB RAM / 500GB 7200 SATA II Hard drive DVD RW 18X multi dual NVIDIA GeForce 8500GT ....
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 16th Apr 2009 11:40
You may also want to consider having enemystate be an array.

E.g.
Dim enemystate(10)
Would allow you to keep track of the state of ten different enemies, so each can do a different thing.

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 16th Apr 2009 17:04
And the final piece of the puzzle is to use a FOR-NEXT loop to make sure all your enemies go through the function





Monk
16
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 16th Apr 2009 17:24
Have an array thats big enough for all your enemies, ie dim enemystate(100) for 100 enemies.

Then, in a For - Next loop from enemy 1 to your last enemy, if the enemystate array for that enemy is 1, do the loop, else not.

for 100 enemies



David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 19th Apr 2009 21:55
thanks so much! but i dont know anything about arrays.

can anyone give me a small example on making an array,using the array with a state (to reuse it) where maybe a box moves changes color then moves back?? with like 10 boxes???

Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 20th Apr 2009 00:01


then something like



"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 20th Apr 2009 02:55 Edited at: 20th Apr 2009 04:09
A Tutorial on Arrays

A Tutorial on Functions

Maybe those will help .

There are some others in the TUTORIALS THREAD (see TDK's section)


Anyway, if you still want to use a gosub you could always do it like this:



And here's your gosub. Note how the exact same variable "e" is used.




Or, as a function:



And here's your actual function. Note how the variable used within the function can be different from the one used on the outside, so long as you put the outside variable in the "input" part of the function:


If this doesn't make any sense, you should try reading a tutorial or two. If you still don't understand after that then just ask .

<---Spell casting battle game!
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 20th Apr 2009 18:32
well u know i almost got it working last night. i had 2 enemies,but the 2nd enemy had the animation.it was like whichever enemy my player was closest to,then the gosub made that enemy attack and act normally. ill figure it out eventually,thanks for all the help btw!!

im going to try & code it like your example sixty. thanks! ive read your tutorial on arrays btw, good stuff!
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 21st Apr 2009 01:30
Quote: "ive read your tutorial on arrays btw, good stuff! "

Thanks! I hope you can get it working .

<---Spell casting battle game!
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 26th Apr 2009 19:36
well i came up with this code:




it doesnt work the way i want.it still makes all the enemies do the exact same thing.can anyone see what im doing wrong???
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 26th Apr 2009 22:42 Edited at: 26th Apr 2009 22:42
EDIT: Nevermind.

<---Spell casting battle game!
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 26th Apr 2009 22:48 Edited at: 26th Apr 2009 22:51
EDIT: You haven't given each enemy its own state. You've created the array just fine, but you use one variable for all of the enemies so the arrays aren't even being used. When using arrays, you need to refer to specific array "slots" or, as they are called in my tutorial, "dressers". Right now you're just doing the same thing once for each enemy object. Try this, The enemy object numbers and enemy states are both stored in arrays now:



I basically just took your code, and put "(e)" next to every place where your wrote "enemy" or "enemystate". I also changed your for/next variable to "e".

Also, on a side note, you may want to add SYNC ON and SYNC RATE 60 to the top of your code. Then, put SYNC right before the word "loop". It will make things look smoother

<---Spell casting battle game!
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 27th Apr 2009 02:30 Edited at: 27th Apr 2009 02:30
thankyou soooo much sixty squares!!!

thanks!!! it works the way i wanted now.

the only thing i dont understand thou is this why u did this????

:
for e = 1 to 3
enemystate(e)=1
next e

can u explain that? tks!

Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 27th Apr 2009 21:24
He is setting the initial value of each of the 'drawers' in the array.

Before it, you would have:
enemystate(1)=0
enemystate(2)=0
enemystate(3)=0

After, you get:
enemystate(1)=1
enemystate(2)=1
enemystate(3)=1

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
Sixty Squares
18
Years of Service
User Offline
Joined: 7th Jun 2006
Location: Somewhere in the world
Posted: 27th Apr 2009 23:46 Edited at: 27th Apr 2009 23:46
You're welcome .

Dream and Death got it. Whenever you create a new array all of the numbers are set to 0 and the strings are set to "". So, all of the enemies would have a state of 0. Your code doesn't recognize an enemy state of 0. So, I set each enemy's state to 1, mainly because that's what you did in the code you posted .

Basically, I did it for the same reason that you did this:


Only I expanded it to account for enemies number 1,2 and 3.

<---Spell casting battle game!
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 24th Jul 2009 18:50 Edited at: 24th Jul 2009 18:52
hey sixty squares are you out there?

thank you soo much for your help with my array code. i dont know if u remember it was a while ago. but i have a small problem.

i use 4000-6000 for my npc numbers and i cant get the array code we worked on to work with for example..

for n=4000 to 4001

next n

i keep getting an array not found or array subscript error.
do u know how to fix this?? so i can declare the array starts with 4000????
?

i can show my whole code if needed.
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 24th Jul 2009 22:10
Don't forget you can add to any number you want to get the same results without going over your array. Since you know your enemies are always object numbers 4000 - 6000 just add 4000.



Or you can use a multidimensional array and save all the enemy info you need. The following is 101 enemies with 6 pieces of data in one array.



David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 24th Jul 2009 23:28 Edited at: 24th Jul 2009 23:32
well this is the code altered with enemy 4000-4002,it doesnt work.
i keep getting an array error doesnt exist or array subscript error.





i even changed this: dim enemy(3) to... dim enemy(4002)
but that doesnt help.

i also changed this too to 4000 to 4002 but it still has an error..
for e = 1 to 3
enemystate(e)=1
next e


btw i tried what u suggested before i posted this..adding 4000 but that didnt work either.
help someone?
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 24th Jul 2009 23:36
you need to do both:



to:
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 25th Jul 2009 00:09
Why have such large arrays??????

If you know your enemies are in the range 4000-5000, for example.

Then you can do:



"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 25th Jul 2009 00:34
And in David iz cool's case, it would be:




Dream And Death, Is there a way to have an arry be a range from a different starting place?
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 25th Jul 2009 00:41
CoughMist: I don't believe so. DBPro, unlike some other languages (e.g. VB) doesn't even support changing the lowest index to 1.

VB would allow the use of the command Option Base 1, which would fix all arrays to count from 1...in DBPro, they all count from 0.

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 25th Jul 2009 01:23
thankyou so much coughmist & dream & death!! it works great!
David iz cool
19
Years of Service
User Offline
Joined: 21st Sep 2005
Location: somewhere lol :P
Posted: 25th Jul 2009 02:29 Edited at: 25th Jul 2009 02:31
did u know u dont even need the constant?

works with just this:

for e=1 to 1000
enemystate(e+3999)=1
next e
zeroSlave
15
Years of Service
User Offline
Joined: 13th Jun 2009
Location: Springfield
Posted: 25th Jul 2009 03:07 Edited at: 25th Jul 2009 03:19
Quote: "Constants are special tokens that can be defined to hold a fixed value or string. You can use the constants anywhere in your program to specify items of data that are not going to change throughout your programs execution. Constants can be used to increase performance of your programs and make your code easier to read"


No, you don't need them. But its a pretty good idea to do it that way.

Also, arrays are awesome, and sometimes a very important aspect to a program. TYPEs are even more awesomer when used with arrays. Especially if you plan on having tons of things that can be grouped such as:

enemy's state
enemy's speed
enemy's HP
enemy's MP
enemy's x
enemy's Y
enemy's Z
etc.



Also, also... Thanks Dream And Death!
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 25th Jul 2009 03:21
Yeah, I kinda now that I didn't need the constant, lol ^_^

I was trying to make it easy for you.

Constants are very useful tools.....

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001

Login to post a reply

Server time is: 2024-09-28 08:25:06
Your offset time is: 2024-09-28 08:25:06