Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
Player pointers

 
Post new topic   Reply to topic Printable version
 View previous topic  A Ship Limit Bot- and no it won't sex ... Post :: Post MERVBot 38 Tutorial  View next topic  
Author Message
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Nov 11, 2003 7:51 pm    Post subject: Player pointers Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Tue Nov 11, 2003 8:11 pm    Post subject: Reply to topic Reply with quote

Nevermind, asked Catid about this one.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mine GO BOOM
Hunch Hunch
What What
Hunch Hunch<br>What What


Age:41
Gender:Gender:Male
Joined: Aug 01 2002
Posts: 3615
Location: Las Vegas
Offline

PostPosted: Tue Nov 11, 2003 10:43 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Send email
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Wed Nov 12, 2003 6:05 pm    Post subject: Reply to topic Reply with quote

Yep, sorry.

BTW In case anyone wants to do something using my method:
What I did was create an array of player pointers in the class botInfo ("Player * caps[MAX_TEAMS];") and just store pointers in there from events ("caps[team] = p;"). It's a great way if you need to make a list of players. Just make sure you make a function like this one:
Code: Show/Hide
bool botInfo::check_leave(Player *p, int team) //This doesn't have to be a separate function if you don't need it outside of EVENT_PlayerLeave
{
   if (team > setts.teams)      return false;
   if (caps[team] == p)
   {
      caps[team] = NULL;
      //Do stuff
      return true;
   }
   return false;
}

Or, if you don't want to specify a team, then just do a for loop.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
ExplodyThingy
Server Help Squatter


Age:38
Gender:Gender:Male
Joined: Dec 15 2002
Posts: 528
Location: Washington DC
Offline

PostPosted: Wed Nov 12, 2003 10:10 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
50% Packetloss
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Sep 09 2003
Posts: 561
Location: Santa Clarita, California
Offline

PostPosted: Wed Nov 12, 2003 10:27 pm    Post subject: Reply to topic Reply with quote

yah, everything in datatypes.h is very useful.
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Dustpuppy
Server Help Squatter


Age:40
Gender:Gender:Male
Joined: Jan 23 2003
Posts: 215
Location: England
Offline

PostPosted: Thu Nov 13, 2003 10:54 am    Post subject: Reply to topic Reply with quote

A linked list isn't necessary in this case, an array would do the job better.
Back to top
View users profile Send private message Add User to Ignore List Send email Visit posters website
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Thu Nov 13, 2003 6:24 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Dr Brain
Flip-flopping like a wind surfer


Age:39
Gender:Gender:Male
Joined: Dec 01 2002
Posts: 3502
Location: Hyperspace
Offline

PostPosted: Thu Nov 13, 2003 9:53 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List AIM Address Yahoo Messenger MSN Messenger
Plody
Guest


Offline

PostPosted: Fri Nov 14, 2003 8:09 am    Post subject: Reply to topic Reply with quote

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!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Fri Nov 14, 2003 4:03 pm    Post subject: Reply to topic Reply with quote

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
View users profile Send private message Add User to Ignore List Visit posters website
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 29 page(s) served in previous 5 minutes.

phpBB Created this page in 0.472298 seconds : 36 queries executed (91.9%): GZIP compression disabled