SA-MP Forums Archive
i need some help with memcpy - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: i need some help with memcpy (/showthread.php?tid=643339)



i need some help with memcpy - 1fret - 18.10.2017

I got this code from a guy in the script help section i tried it but end up with these errors, i was trying to fix it but nothing seems to work, could someone tell me whats wrong here or even give me a fix for it, i will be trying to do some research on the issue still

PHP код:
ResetVariables(playerid

    
memcpy(pInfo[playerid], pInfo[MAX_PLAYERS], 0sizeof(pInfo[])*4pInfo(pInfo[])); 
 }  
/*
./comps/functions.pwn(2449) : warning 229: index tag mismatch (symbol "pInfo")
./comps/functions.pwn(2449) : error 032: array index out of bounds (variable "pInfo")
./comps/functions.pwn(2449) : error 012: invalid function call, not a valid address
./comps/functions.pwn(2449) : error 029: invalid expression, assumed zero
./comps/functions.pwn(2449) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664              Copyright © 1997-2006, ITB CompuPhase
4 Errors.
*/ 
PHP код:
   memcpy(PlayerTemp[playerid], PlayerTemp[MAX_PLAYERS], 0sizeof(PlayerTemp[])*4PlayerTemp(PlayerTemp[])); 
/*
./comps/functions.pwn(2450) : error 032: array index out of bounds (variable "PlayerTemp")
./comps/functions.pwn(2450) : error 012: invalid function call, not a valid address
./comps/functions.pwn(2450) : error 029: invalid expression, assumed zero
./comps/functions.pwn(2450) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664              Copyright © 1997-2006, ITB CompuPhase
4 Errors.
*/ 
PHP код:
enum ptemps
{
    
isevent,
    
afrozen,
    
OnDuty,
    
OnhDuty,
    
LoginAttempts,
    
Spawned,
    
MaxRcon,
    
pSpawnFreeze,
    
Jetpack,
    
LastShotTick,
    
LastShot,
    
dSpawnedCars,
     
Blindfold,
    
antispawn[MAX_PLAYERS],
    
Family[MAX_PLAYERS],
    
Cigar[MAX_PLAYERS],
    
Blindfolded[MAX_PLAYERS],
    
Rope[MAX_PLAYERS],
    
Dice[MAX_PLAYERS],
}
new 
PlayerTemp[MAX_PLAYERS][ptemps];
enum PlayerInfo
{
    
Pass,
    
Cash,
    
Bank,
    
Admin,
    
Helper,
    
Kills,
    
Deaths,
    
Score,
    
Token,
    
Banned,
      
PurLot,
    
LastSpawnedCar,
    
dCars[MAX_CAR_SPAWNS],
     
Spec,
       
Warns,
       
Frozen,
       
cTime,
    
Hours,
    
Minutes,
    
Muted,
    
pMuted,
       
pHouse,
    
pVHouse,
     
VIP,
    
Plic,
    
Weplic,
    
JailedTime,
    
Jailed,
    
pBiz,
    
pVBiz,
    
perm,
     New,
    
Arrested,
    
RefPoints,
    
Gate[3],
    
pVeh,
    
vModel,
    
Float:vX,
    
Float:vY,
    
Float:vZ,
    
Float:vA,
    
vC1,
    
vC2,
    
vPJ,
    
pVehMod[14],
    
vLocked,
    
// 3 Car Slot Begins
    
pBVeh,
    
vBModel,
    
Float:vBX,
    
Float:vBY,
    
Float:vBZ,
    
Float:vBA,
    
vBC1,
    
vBC2,
    
vBPJ,
    
pBVehMod[14],
    
vBLocked,
    
pVVeh,
    
vVModel,
    
Float:vVX,
    
Float:vVY,
    
Float:vVZ,
    
Float:vVA,
    
vVC1,
    
vVC2,
    
vVPJ,
    
pVVehMod[14],
    
vVLocked,
    
pFam,
    
pFamRank
}
new 
pInfo[MAX_PLAYERS][PlayerInfo]; 



Re: i need some help with memcpy - StrikerZ - 18.10.2017

Quote:
Originally Posted by RIDE2DAY
Посмотреть сообщение
As you're not copying data from another array you don't need memcpy at all, just go this easier way:
PHP код:
ResetVariables(playerid)
{
    new 
tmp_array[PlayerInfo]; 
    
pInfo[playerid] = tmp_array;
    
/*
    new another_example[ptemps];
    PlayerTemp[playerid] = another_example;
    */

Your code doesn't make sense by the way, you're using an invalid source and wrong sizes for the destination array.
PHP код:
memcpy(pInfo[playerid], pInfo[MAX_PLAYERS], 0sizeof(pInfo[])*4sizeof(pInfo[]));   
memcpy(PlayerTemp[playerid], PlayerTemp[MAX_PLAYERS], 0sizeof(PlayerTemp[])*4sizeof(PlayerTemp[])); 
OP: Here's the fixed code, I made a lil' mistake at the end.

@RIDE2DAY;
It's used to set all the enum variables to zero, a little mistake in sizes changed a lot.


Re: i need some help with memcpy - 1fret - 18.10.2017

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
PHP код:
memcpy(pInfo[playerid], pInfo[MAX_PLAYERS], 0sizeof(pInfo[])*4sizeof(pInfo[]));   
memcpy(PlayerTemp[playerid], PlayerTemp[MAX_PLAYERS], 0sizeof(PlayerTemp[])*4sizeof(PlayerTemp[])); 
OP: Here's the fixed code, I made a lil' mistake at the end.

@RIDE2DAY;
It's used to set all the enum variables to zero, a little mistake in sizes changed a lot.
Im still getting the same errors


Re: i need some help with memcpy - StrikerZ - 20.10.2017

Quote:
Originally Posted by RIDE2DAY
Посмотреть сообщение
I don't know if it works or not, but as I said before, why are you using pInfo[MAX_PLAYERS] as source? Isn't MAX_PLAYERS an invalid index for accesing the pInfo array? Oh, it is.

On the other hand, probably the correct way would be pInfo[MAX_PLAYERS - 1] but how do you know that there isn't garbage data left there by a player who used that player ID (499 = MAX_PLAYERS - 1)? Assuming your slots don't reach MAX_PLAYERS it would be safe, but the code wouldn't be optimal in that case. Redefine MAX_PLAYERS!

This isn't important at all, but why are you using sizeof for the last two parameters? Didn't you declare your array using MAX_PLAYERS as cells amount? Oh, you did!

So yes, it should look like this:
PHP код:
memcpy(pInfo[playerid], pInfo[MAX_PLAYERS 1], 0MAX_PLAYERS 4MAX_PLAYERS); 
This might work but it's not safe! Use this method:
PHP код:
new empty_arr[your_enum];
yourArr[index] = empty_arr
Have a nice day.
I already told him to make the MAX_PLAYERS+1 in the enum before this thread, so yeah the answer is in front of you.
And
https://sampforum.blast.hk/showthread.php?pid=3723254#pid3723254


Re: i need some help with memcpy - StrikerZ - 20.10.2017

Quote:
Originally Posted by RIDE2DAY
Посмотреть сообщение
Okay, seems that after all that's not your argument. Yashas is wrong there.
Might be, I've learnt to do that from that thread.