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.

DarkBASIC Professional Discussion / Something like "If mesh=x". Can it be done?

Author
Message
Opposing force
20
Years of Service
User Offline
Joined: 10th Aug 2005
Location: England
Posted: 16th Sep 2010 11:58
Probably a really easy thing to do but I just can't figure it out. I've got say 5 enemy character models loaded into the memory and I want each one to have a different attribute set based on their mesh. Whenever an enemy is spawned then the program randomly picks one of the objects to clone and place in the level. Got that part sorted but what I can't figure out is how to accurately assign behavioural variables based on which mesh was cloned. I want to do something like this (fake code)

If mesh=1 then enemy_stats$="Aggressive"
If mesh=2 then enemy_stats$="Coward"
If mesh=3 then enemy_stats$="Stupid"
etc...

I just need someone to send me in the right direction really.
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 16th Sep 2010 12:06 Edited at: 16th Sep 2010 12:07
Can't you just save each type (assigned a different number) to a file, and then check which value the random number is, and then look for that number in your file?

Cheers

Slayer rules!!! Yeaaah, man!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Sep 2010 12:10 Edited at: 16th Sep 2010 12:49
You should make an array for your characters properties, or enemies - depending on how you handle it (sometimes I use the enemy handling for players as well). Maybe a typed array, assuming you have 64 enemies...

Type enemytype
X# Y# Z#
XS# YS# ZS#
Direction#
Smarts
Object
Mode
Endtype
Dim enemy(64) as enemytype

Now most of that might not be necessary, it's just the way I do things, the part that your interested in is the Smarts component of the enemy type. For each character, you could set this when spawning an enemy. For instance, you might do something like this:

Function spawn_enemy()

e=0
while enemy(e).mode=0 and e<64 : inc e : endwhile

mesh=rnd(2)+1
if mesh=1 then enemy(e).Smarts=0
if mesh=2 then enemy(e).Smarts=1
if mesh=3 then enemy(e).Smarts=2
enemy(e).mode=1

Endfunction

Then you would call spawn)enemy, and store the Smarts of that enemy, which can be checked when updating the enemy, maybe even use it as a factor in AI, like the speed at which an enemy can move, or turn, or a randomised factor for whether or not they attack.

Health, Ammo, and bacon and eggs!
Opposing force
20
Years of Service
User Offline
Joined: 10th Aug 2005
Location: England
Posted: 16th Sep 2010 12:20
Thanks for replying so quickly guys.

@The Slayer: What you said does make sense, thanks for helping. I'll check it out.

@Van B: Thanks for explaining your code to me. I knew I'd have to get my head round arrays and types some time. I'll have a look at your example in greater detail and I'm sure it's going to help immensely. Cheers.

Login to post a reply

Server time is: 2026-07-22 12:41:21
Your offset time is: 2026-07-22 12:41:21