Author |
Message |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Nov 11, 2003 7:51 pm Post subject: Player pointers |
 |
|
|
|
Are the pointers (eg: Player *p) created by bot events valid until the player leaves the arena, or do they go away after a time limit?
I created an array of player pointers, but there's an error, I think the pointers are invalid... _________________ This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Tue Nov 11, 2003 8:11 pm Post subject: |
 |
|
|
|
Nevermind, asked Catid about this one. |
|
Back to top |
|
 |
Mine GO BOOM Hunch Hunch What What

Age:41 Gender: Joined: Aug 01 2002 Posts: 3615 Location: Las Vegas Offline
|
Posted: Tue Nov 11, 2003 10:43 pm Post subject: |
 |
|
|
|
Cyan~Fire wrote: | Nevermind, asked Catid about this one. |
If you do fix your own problem, explain it. That way others can understand their problems if they search for it, or learn new things.
For the above reason, here I go:
The pointers should remain valid as long as the user is in the arena, assuming the bot core does not do some funky things randomly. Once he leaves the arena, the pointer itself (if you made a local copy of it) will still point to something, just there won't be any valid data there, thus causing errors. So what you'll need to do is setup a function to clear, or NULL, your local pointer copies whenever you get the player-left calls. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
|
Back to top |
|
 |
ExplodyThingy Server Help Squatter
Age:38 Gender: Joined: Dec 15 2002 Posts: 528 Location: Washington DC Offline
|
Posted: Wed Nov 12, 2003 10:10 pm Post subject: |
 |
|
|
|
Or just use catid's linked list. Its much less likely to cause an error. For example, say you setup someone in caps[0] through [5], and player [3] leaves. When you iterate through the list, youll succeed on accessing info in caps[0] through 2, but in 3 therell be a null pointer. however, 4 and 5 will still exist. Cats list allows for a Delete method which goes ahead and takes the next item's previous and points it to the one previous, and the previsous's next item and points it to the next. _________________ There are no stupid question, but there are many inquisitive idiots.
Loot
Dr Brain> I hate clean air and clean water. I'm a member of Evil Conservitive Industries |
|
Back to top |
|
 |
50% Packetloss Server Help Squatter

Age:40 Gender: Joined: Sep 09 2003 Posts: 561 Location: Santa Clarita, California Offline
|
Posted: Wed Nov 12, 2003 10:27 pm Post subject: |
 |
|
|
|
yah, everything in datatypes.h is very useful. |
|
Back to top |
|
 |
Dustpuppy Server Help Squatter

Age:40 Gender: Joined: Jan 23 2003 Posts: 215 Location: England Offline
|
Posted: Thu Nov 13, 2003 10:54 am Post subject: |
 |
|
|
|
A linked list isn't necessary in this case, an array would do the job better. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Thu Nov 13, 2003 6:24 pm Post subject: |
 |
|
|
|
Yeah, linked list would mean making copies of every single player (lots of memory) and making sure you delete the entries, generally more complicated. I could see using linked list if I needed the players after they leave, but I don't. |
|
Back to top |
|
 |
Dr Brain Flip-flopping like a wind surfer

Age:39 Gender: Joined: Dec 01 2002 Posts: 3502 Location: Hyperspace Offline
|
Posted: Thu Nov 13, 2003 9:53 pm Post subject: |
 |
|
|
|
Uh, ever hear of pointers? And an array would have the same problem.
Choosing which data structure to use depends highly on the application. If you are going to have relitivly few inserts and deletes (random access), then an array/vector is the way to go, but if instead lookups are less common and you need to do a lot of changing, linked lists are the structure of choice. _________________ Hyperspace Owner
Smong> so long as 99% deaths feel lame it will always be hyperspace to me |
|
Back to top |
|
 |
Plody Guest
Offline
|
Posted: Fri Nov 14, 2003 8:09 am Post subject: |
 |
|
|
|
Theyre all pointers to the same block of memory. It wont make new copies of a player in the memory with either case, itll simply make a new refenerence to the same section. If you try to access the player from either of the list forms if the player has left, the core has already deleted the player's info in memory, and youll end up with pointers pointing to no where, and kablow.
The while loop in cats ll checks to make sure the parse pointer exists, which is a node of the list. You should add a "if(parse->item)" in this case, the item being the template class pointing to the Player. If the player doesnt exist, it will resolve false, save you from accessing nonexistant data, and allows you delete the node of the linkedlist. |
|
Back to top |
|
 |
Cyan~Fire I'll count you!

Age:37 Gender: Joined: Jul 14 2003 Posts: 4608 Location: A Dream Offline
|
Posted: Fri Nov 14, 2003 4:03 pm Post subject: |
 |
|
|
|
I just don't see why I should use something more complicated when it doesn't need it.
And about the invalid pointers, with that function I have, a player struct shouldn't be removed without that thing activating. It's worked so far. |
|
Back to top |
|
 |
|