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 / AI function help

Author
Message
aks74u
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: arizona
Posted: 21st Jul 2004 08:27
i took froogles idea and made some functions concerning ai.



i have messed aound with this for a while can't seem to make it work. I am pretty sure it has something to do with the "aialert" function beacuse it has to return a 1 or 0 but it doesn't.

thx for your help and sorry about another ai question.

Over And Out.
GameKit
21
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 21st Jul 2004 10:32 Edited at: 21st Jul 2004 10:34
I noticed a few potential problems, try changing your code to this...



well... I hope I helped

The computer isn't an addiction, its more of a mental and social dependancy.
aks74u
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: arizona
Posted: 21st Jul 2004 13:26
no its doesn't work but thanks so much anyway. i'll messing around witht his now.

Over And Out.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 21st Jul 2004 13:52 Edited at: 21st Jul 2004 13:54
Hi!

Okay, I think your problem is a simple one: the "dist" variable isn't defined as a global. That means, although distance() does return the correct value, it's not being passed to aialert() for proper detection. Either declare dist a global or change aialeart to;

function aialert(dist)
if dist<1000
shoot=1
color object 104,RGB(255,0,0)
point object 104,gunx#,guny#,gunz#
move object 104,3
else
shoot=0
endif
endfunction shoot

and provide the function the dist(ance) returned by distace() as in;

dist = distance()

if aialeart(dist) = 1 then aishoot()

and so on...

S.

Any truly great code should be indisguishable from magic.
aks74u
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: arizona
Posted: 21st Jul 2004 14:54 Edited at: 21st Jul 2004 14:57
i do have dist declared. does it have to do with maybe dist but change it to dist?



(edit)
what do you mean y dist(ance) am i just stupid or am i missing something?

Over And Out.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 22nd Jul 2004 04:42
Well, I meant passing the value returned by disance() to aialert() as in the sample given. Since distance() returns a value that you are not presently using, it gets dumped. But aialeart() needs the value of dist to operate and according to the code posted dist is not global. That means, when aialert() tries to access dist, it is zero. (All functions start with all variables equal to zero unless they are global or passed ones. Arrays are always global, so distance() works as written.) So once again, the changes are;

dist = distance()

if aialeart(dist) = 1 then aishoot()

and...

function aialert(dist)
if dist<1000
shoot=1
--etc...
endfunction

S.

Any truly great code should be indisguishable from magic.
aks74u
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: arizona
Posted: 22nd Jul 2004 16:33
ok i messed around with it and print the dist and shoot on screeen and if i change the

if dist<1000

to a higher number so the cube is in distance the code works right but the distance reading stays at the point i started not the current position of me if i move around. i took out the vaiables to make sure they weren't the problem but i got the same result.
do you think my dist function is wrong?



thx again

Over And Out.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 23rd Jul 2004 08:57
Well, to answer that question I'd have to ask you -- what object is you? Distance() returns the value between objects 104 and 102, is one of them you? Is one of them the enemy? You have to be specific here before I can know why dist is not changing.

Any truly great code should be indisguishable from magic.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 24th Jul 2004 04:25 Edited at: 24th Jul 2004 04:27
Okay, I have looked at the code a little more and have determined that object 102 is you and 104 is the enemy, while 105 is the bullet to be fired...

But there are other concerns as well here. The first is, you can't print "shoot" in the same manner as you're printing "dist" unless it too is a global, since I'm assuming you want it to say "1" is aialert() is trying to fire. That's the same problem as you had with dist, it's not global unless you've declared it as such and setting a value inside a function does not mean it gets passed to the total program for the same reason. So for that you'd need;

shoot=aialeart(dist)
print shoot
if shoot = 1 then aishoot()

And while we're on the variables here, the aishoot will only show the bullet if bulletfire equals zero, and then will decrement the value to 99 and leave it there forever! Why? Because the decrement command is inside the same if condition. Unless you have another place in your main loop where you decrement bulletfire and advance the bullet movement, then reset bulletfire back to 100, the bullet will never move. And that TOO must be declared as global, because the value will be ZERO when the aishoot() function starts if it is not.

So, assuming you've made all these values globals... let's see why your distance value isn't changing.

For that, I am assuming that the value of 1000 or even 3000 is "too close." What I mean is, the player and the enemy are "within range" of shooting at each other if you set a value of 1000 or 3000, so the enemy object tries to "follow" the player constantly. This means that dist will always be the same value as the player moves, (unless you move closer to the enemy) because the enemy is changing position with the player.

Try setting the value to like 500 or 100 -- meaning you have to get *really close* before the enemy follows you, which takes place in aialert(). Then you should see dist change as you move around, until you get close enough to have the enemy start following.

Good luck...
s.

Any truly great code should be indisguishable from magic.
aks74u
20
Years of Service
User Offline
Joined: 2nd Jun 2004
Location: arizona
Posted: 24th Jul 2004 16:17
im on vacation right now so ican't really do anythiing but i can still learn. do i declare variables as globals at the top of a prgram?

wow i'm reading this over and over again to get it in my head. someday i hope to be good enough to help people like me out just as you do.

i think if i can get all this down i can move on to more challeging things.

thx!

Over And Out.
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 24th Jul 2004 18:29
Yes, in DBPro you declare these value as global at the top of the program as in;

global dist
global shoot
global bulletfire

...and so on. In DB Classic these need to be array values, as in;

dim dist(0)
Dim shoot(0)
dim bulletfire(0)

...and so on, which dark edit does automatically.


As for helping out, well, I'm an old hand at programming, and though I am still learning the ins and outs of Dark Basic I love it and know a little about, it and Basic programming style. So I help when I can, and learn when I must. It's all good, for someone somewhere will think of of something I haven't, so we all learn together.

Have a good vacation, and good luck with the code,
Sandra.

Any truly great code should be indisguishable from magic.

Login to post a reply

Server time is: 2024-09-22 17:29:58
Your offset time is: 2024-09-22 17:29:58