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
baffled by this coding

 
Post new topic   Reply to topic Printable version
 View previous topic  clientset.h What is override Post :: Post How to check if a player is in a safety?  View next topic  
Author Message
Reaem
Newbie


Joined: Oct 02 2005
Posts: 9
Offline

PostPosted: Wed Mar 12, 2008 4:13 pm    Post subject: baffled by this coding Reply to topic Reply with quote

Code: Show/Hide
void Cbuyship(const char *tc, const char *params, Player *p, const Target *target)
{
   int ship = atoi(params);
   if (ship < 1 || ship > 8)
      return;
   
   ship--; //for convenience
   
   //cost checking
   if (!Spend_Pts(p, ship_costs[ship]))
      return;
   else
   {
      void *v = HashGetOne(docks, p->name);
      dock d;
      d = (dock)*v;
      
      if (!d)
      {
         d = {0,0,0,0,0,0,0,0};
         d[ship] = 1;
         HashReplace(docks, p->name, d);
      }
      else
      {
         d[ship] = d[ship] + 1;
      }
   }
}


I get the following errors:
../RTZ/RTZ.c: In function `Cbuyship':
../RTZ/RTZ.c:190: warning: dereferencing `void *' pointer
../RTZ/RTZ.c:190: error: cast specifies array type
../RTZ/RTZ.c:194: error: syntax error before '{' token

../RTZ/RTZ.c:198: error: syntax error before "else"

190 is the line with d = (dock)*v;

The problem is, I'm not sure what to do with the void pointer to cast it into the dock object (If I even need to do that).
dock is just a simple: typedef int dock[8];

I've been programming for awhile, but I'm not certified or even a real c veteran and the void pointer cast to dock type is really owning me.
Thanks in advance,
-R
_________________
-JP
Back to top
View users profile Send private message Add User to Ignore List Visit posters website AIM Address
Dr Brain
Flip-flopping like a wind surfer


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

PostPosted: Wed Mar 12, 2008 4:26 pm    Post subject: Reply to topic Reply with quote

what's wrong with d = v?

You can't initialize non-static arrays like that on like 194.
_________________
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
Agile
Guest


Offline

PostPosted: Wed Mar 12, 2008 6:44 pm    Post subject: Reply to topic Reply with quote

d=v doesn't work, I've tried countless variations of castings and allocation orders and nothing I do can make this work.
Same incompatible types error
Back to top
Bak
?ls -s
0 in


Age:26
Gender:Gender:Male
Joined: Jun 11 2004
Posts: 1826
Location: USA
Offline

PostPosted: Wed Mar 12, 2008 6:58 pm    Post subject: Reply to topic Reply with quote

Code: Show/Hide

void *v = HashGetOne(docks, p->name);
  int* d = (int*)v;
  int x;
 
  if (!d)
  {
    d = new int[8];
   
    for (x = 0; x < 8; ++x)
      d[x] = 0;
   
    d[ship] = 1;
    HashReplace(docks, p->name, d);
  }
  else
  {
    d[ship] = d[ship] + 1;
  }


just make sure the memory gets freed somewhere
_________________
SubSpace Discretion: A Third Generation SubSpace Client
Back to top
View users profile Send private message Add User to Ignore List AIM Address
Samapico
No, these DO NOT look like penises, ok?


Joined: May 08 2003
Posts: 1252
Offline

PostPosted: Wed Mar 12, 2008 11:56 pm    Post subject: Reply to topic Reply with quote

how about
Code: Show/Hide

d = (int*)v;


d is a dock object, or a pointer to an int (int*).
So you want to convert a void* to a int*
(int*)v should do just that.

And the array initialization doesn't work either. If you really need the values to be 0, you could use ZeroMemory
something like:
Code: Show/Hide
ZeroMemory(d,8*sizeof(int) );

_________________
(Insert a bunch of dead links here)
Back to top
View users profile Send private message Add User to Ignore List
Smong
Server Help Squatter


Joined: 1043048991
Posts: 0x91E
Offline

PostPosted: Thu Mar 13, 2008 9:16 am    Post subject: Reply to topic Reply with quote

Code: Show/Hide
d = (dock)*v;

This might work:
Code: Show/Hide
d = *(dock*)v;

But as pointed out before the rest of your code is a little iffy anyway.
_________________
ss news
Back to top
View users profile Send private message Add User to Ignore List Visit posters website MSN Messenger
Agile
Guest


Offline

PostPosted: Thu Mar 13, 2008 5:19 pm    Post subject: Reply to topic Reply with quote

Yeah, the void pointers and arrays by themselves I can deal with, but putting them together scrambles my brain.
I eventually just decided to make it a struct similar to BotData with an array in it =( Maybe I can optimize this later on but I want to get a working server soon.
Thx everyone
Back to top
tcsoccerman
Server Help Squatter


Age:33
Gender:Gender:Male
Joined: Jan 15 2007
Posts: 694
Location: Atlantis
Offline

PostPosted: Thu Mar 13, 2008 6:58 pm    Post subject: Reply to topic Reply with quote

if this is in devcpp, i've had problems where i forget to make the projecta "c" project instead of a "c++" project. i have spent countless hours trying to figure out the problem..
Back to top
View users profile Send private message Add User to Ignore List Send email AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> ASSS 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: 154 page(s) served in previous 5 minutes.

phpBB Created this page in 0.475081 seconds : 32 queries executed (93.4%): GZIP compression disabled