SA-MP Forums Archive
SSCANF Loading hudge data +1 Rep - 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: SSCANF Loading hudge data +1 Rep (/showthread.php?tid=334298)



SSCANF Loading hudge data +1 Rep - Ubuntu - 14.04.2012

I'm wondering if it's possible to load hudge amount of data with SSCANF, because I know it's very fast and you know...

Let's say I want to load this with sscanf (from VX-RP Script, example only...):

Код:
enum playervEnum {
	Float: pHealth,
	Float: pArmour,
	Float: pPos[3],
	pPassword[129],
	pStatus,
	pAge,
	pMoney,
	pAdminLevel,
	pInterior,
	pLevel,
	pSkinSet,
	pCarID,
	pAnticheatExemption,
	pTabbed,
	pCarWeapons[5],
	pCarLicensePlate[32],
	pCarTrunk[2], // Cash & mats
	pPhoneCredit, // Will be done in seconds.
	pWalkieTalkie, // -1 = no walkie, 0 = switched off
	pSpectating,
	pSpecSession,
	pConnectedSeconds,
	pSpamCount,
	pFishing,
	pMuted,
	pVirtualWorld,
	pFish,
	pBanned,
	pTazer,
	pEvent,
	Float: pCarPos[4],
	pReport,
	pPrisonTime,
	pPrisonID, // 3 = IN CHARACTER JAIL! (future reference)
	pHackWarnTime,
	pHelperDuty,
	pReportMessage[64],
	pPlayingHours,
	pSkin,
	pJob,
	pRope,
	pAccent[40],
	pWarning1[32],
	pWarning2[32],
	pWarning3[32],
	pPhoneNumber,
	pSkinCount,
	pSeeOOC,
	pOOCMuted,
	pNewbieTimeout,
	pTutorial,
	pWeapons[13],
	pOutstandingWeaponRemovalSlot,
	pJetpack,
	pBankMoney,
	pHackWarnings,
	pEmail[255], // because this is the max length for a valid email.
	pSeconds,
	pFightStyle,
	pInternalID,
	pJobDelay,
	pGender,
	pNewbieEnabled,
	pFirstLogin,
	pAdminDuty,
	pHelper,
	pCarColour[2],
	pMatrunTime,
	pAdminName[MAX_PLAYER_NAME],
	pNormalName[MAX_PLAYER_NAME],
	pPhoneBook,
	pCheckpoint,
	pPMStatus,
	pOnRequest,
	Text3D: pAFKLabel,
	pGroup,
	pCarModel,
	pCarMods[13],
	pCarPaintjob,
	pCarLock,
	pVIP,
	pGroupRank,
	pDropCarTimeout,
	pMaterials,
	pJobSkill[2],
	pHospitalized,
	pFreezeTime, // Seconds. Set it to -1 if you want to permafreeze.
	pFreezeType, // 0 = not frozen (obviously), 1 = tazed, 2 = cuffed, 3 = admin frozen, 4 = tied
	pDrag,
	pAnimation,
	pPhoneStatus, // togged on/off
	pPhoneCall,
	pConnectionIP[32],
	pSeeWhisper,
	pCrimes,
	pArrests,
    pWarrants,
	pBackup,
}
This is a lot of variables I'm wondering how I can load it with sscanf without have a hudge amount of string length like str[1024];

I'm willing to give reputation.


Re: SSCANF Loading hudge data +1 Rep - Ubuntu - 14.04.2012

Come on guys, it's a simple questions, I'm just trying to figure out.


Re: SSCANF Loading hudge data +1 Rep - iggy1 - 14.04.2012

If your planning on using sscanf for all that data the string will HAVE to be large enough to hold the data. It's as simple as that, no way around it. You could call sscanf a few times with a smaller array but that's much less efficient than using a large array.


Re: SSCANF Loading hudge data +1 Rep - Joe Staff - 14.04.2012

I suggest you make a global variable for it. Although it will be stuck in memory as unused, it won't resort in stacking or memory leakage.

pawn Код:
new gLargeString[4096];
stock myfunction()
{
    gLargeString=""; // erase string
    for(new spam=0;spam<40;spam++)strcat(gLargeString,"Bacon :D ");
}



Re: SSCANF Loading hudge data +1 Rep - Ubuntu - 14.04.2012

The problem is that if the string is very large it will causes problems, I'm wondering if it's possible to do it in another way.


Re: SSCANF Loading hudge data +1 Rep - iggy1 - 14.04.2012

What problems does it cause? (because it really shouldn't)


Re: SSCANF Loading hudge data +1 Rep - Ubuntu - 14.04.2012

Try it yourself, load all these data into 1 row of sscanf and you will see what will happen.


Re: SSCANF Loading hudge data +1 Rep - iggy1 - 14.04.2012

Quote:
Originally Posted by Ubuntu
ПоÑмотреть Ñообщение
Try it yourself, load all these data into 1 row of sscanf and you will see what will happen.
Erm i asked you a question so people can help you. I really can't be bothered writing all that code when you could just tell me whats wrong with it.


Re: SSCANF Loading hudge data +1 Rep - Ubuntu - 14.04.2012

Well, what's wrong with it is that the string buffer overflow.


Re: SSCANF Loading hudge data +1 Rep - iggy1 - 14.04.2012

Make the string larger then. If the string isn't global it will be removed from memory anyway.