Mirage Source
http://www.miragesource.net/forums/

Binary Saving Question
http://www.miragesource.net/forums/viewtopic.php?f=201&t=4250
Page 1 of 2

Author:  Anthony [ Wed Sep 03, 2008 6:09 pm ]
Post subject:  Binary Saving Question

I changed the way MS was saving files and decided to save all the shops in one and spells in one etc.

After some testing I noticed that the server only clears the first shop, spell, item. It doesn't clear the rest after that. I think there is something wrong with my method?

Here is spells for example and since the SpellEditor LevelReq has to be set to 1 because the scroll bars minimum is 1 it gives me an error when I try to edit any spells after the first one. I hope this is making sense :P.

So I clear the spell.
Code:
Sub ClearSpell(ByVal Index As Long)
    Call ZeroMemory(ByVal VarPtr(Spell(Index)), LenB(Spell(Index)))
    Spell(Index).Name = vbNullString
    Spell(Index).LevelReq = 1 ' Needs to be 1 for spell editor
End Sub


Setting LevelReq to 1 like the original MS did. Then my saving and loading code.

Code:

Sub SaveSpells()
Dim i As Long
 
    Call SetStatus("Saving Spells... ")
        For i = 1 To MAX_SPELLS
            If Not FileExist(GENERAL_PATH & "spells.dat") Then
                Call SaveSpell(i)
            End If
        Next i
End Sub

Sub SaveSpell(ByVal SpellNum As Long)
Dim FileName As String
Dim f As Integer
Dim StartByte As Long

    FileName = App.Path & GENERAL_PATH & "spells.dat"
    f = FreeFile
 
    StartByte = LenB(Spell(SpellNum)) * (SpellNum - 1) + 1
 
    Open FileName For Binary As #f
        Put #f, StartByte, Spell(SpellNum)
    Close #f
End Sub

Sub LoadSpells()
Dim FileName As String
Dim StartByte As Long
Dim i As Long
Dim f As Long

  Call CheckSpells
 
    For i = 1 To MAX_SPELLS
       
        FileName = App.Path & GENERAL_PATH & "spells.dat"
        f = FreeFile
 
        StartByte = LenB(Spell(i)) * (i - 1) + 1
 
        Open FileName For Binary As #f
            Get #f, StartByte, Spell(i)
        Close #f

    Next i
End Sub


Thanks for the help! :D

Author:  Lea [ Wed Sep 03, 2008 6:47 pm ]
Post subject:  Re: Binary Saving Question

Get real familiar with the file structure, and look at your file in a hex editor like XVI32. Figure out if it's saving the full length of the spell, or if it's overwriting the last few bytes. I think it's your startbyte, because that causes a lot of goofy problems if it's off by but one number.

You're on the right track, just got to debug it.

Author:  Anthony [ Wed Sep 03, 2008 9:32 pm ]
Post subject:  Re: Binary Saving Question

Using the hex editor you said it's only showing that only one of the Spells is saved and that's the first one. It's the same with all the other files too, but that's not really surprising since they are all saved the same way.

So for some reason it's not even saving all the maximums of the data. It's just saving the first one then going to the next file.

Also, I was under the impression using LenB the way I did gathers all the bytes automatically from the UDT?

Author:  Lea [ Wed Sep 03, 2008 10:26 pm ]
Post subject:  Re: Binary Saving Question

My valkoria source is on www.valkoria.com and this is done in it if you want to take a peek. MY WAY IS NOT GOOD! There's better ways to do it, but you can compare and figure it out. You're doing the better way of calculating the start byte ;)

Author:  Anthony [ Wed Sep 03, 2008 11:14 pm ]
Post subject:  Re: Binary Saving Question

So the reason it wasn't saving them all I guess was because I had that If Not FileExist check inside of the For loop. I moved it outside of it and it seems to be working fine now.

Author:  Lea [ Thu Sep 04, 2008 5:13 am ]
Post subject:  Re: Binary Saving Question

Like I said in GTalk, I had a hunch what it was. I'm glad you found it on your own! I'm doubly glad that I was right :D

Author:  Rian [ Thu Sep 04, 2008 9:49 pm ]
Post subject:  Re: Binary Saving Question

So I just added Anthony's subs for saving 1 spell file, just for a little testing. Currently, all my spells are saved in separate binary files. All together, the the file siles for my spells folder is about 7kb. My single spells file though, is 14kb.

I haven't really done anything major, just added a command button to save the spells differently. Why is there such a gap in the file size?

Author:  Lea [ Thu Sep 04, 2008 10:23 pm ]
Post subject:  Re: Binary Saving Question

Might have some bug saving them twice or something.

The total size should be quite significantly smaller in one file.

Author:  Anthony [ Fri Sep 05, 2008 6:17 pm ]
Post subject:  Re: Binary Saving Question

So now I am determined to find out whats going on and so far I have this.

Saving to multiple files as default in MS4, MAX_SPELLS = 255, default MS Spell UDT
Bytes - 7,395

Saving to one file, using LenB to determine the total bytes, MAX_SPELLS = 255, default MS Spell UDT.
Bytes - 12,220

Saving to one file, counting my own bytes from the UDT, MAX_SPELLS = 255, default MS Spell UDT.
Bytes - 7,395

So Dave.. How come LenB is screwing me haha.

Author:  Lea [ Fri Sep 05, 2008 7:27 pm ]
Post subject:  Re: Binary Saving Question

try using just Len()

Author:  Rian [ Fri Sep 05, 2008 7:59 pm ]
Post subject:  Re: Binary Saving Question

Using len() cut my 13.9kb file down to 8.21kb

Author:  Lea [ Fri Sep 05, 2008 8:16 pm ]
Post subject:  Re: Binary Saving Question

did it save and load correctly?

Author:  Anthony [ Sat Sep 06, 2008 12:54 am ]
Post subject:  Re: Binary Saving Question

Using Len() is now the same size as if I were to count the bytes myself.

It is saving and loading correctly. Any way we can make it smaller? xD.

Author:  Jacob [ Sat Sep 06, 2008 12:58 am ]
Post subject:  Re: Binary Saving Question

Make sure to use the smallest types in your UDT?

Author:  Anthony [ Sat Sep 06, 2008 6:32 am ]
Post subject:  Re: Binary Saving Question

How do you save only the string size needed instead of the entire 20 bytes every time?

Author:  Lea [ Sat Sep 06, 2008 7:46 am ]
Post subject:  Re: Binary Saving Question

it makes things a bit more complicated

Instead of just Get #f, , Shop

You need to do all the variables seperately

Put the length of the string
Put the string
Put the rest of it

Then to read
Get the length of the string
Create a byte array of this size
Get the string to the byte array
Covert to string
Get the rest of it

It effectively eliminates that 20 character limit, and gets rid of any wasted space.

Author:  wanai [ Mon Dec 13, 2021 3:10 pm ]
Post subject:  Re: Binary Saving Question

инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинйоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфо
инфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоинфоsemiasphalticflux.ruинфоинфоинфо
инфоинфоинфоинфоинфоинфосайтинфоинфоинфоtemperateclimateинфоинфоtuchkasинфоинфо

Author:  wanai [ Wed Feb 09, 2022 10:34 pm ]
Post subject:  Re: Binary Saving Question

Birl560BettCHAPIntrSinnPeteEtheRamaDiscKeikHenrAldoJamiKreoAtlaTescRondBianSwisEsotDeanGraf
RondMachRondFavoDessErbaVoluDemoXVIIEpilErleAvaiJeweDoctGabrPatrDiadGlisMipaSebuJeanVisiCred
GreeDolbKeviJeweLaugMagiThinMudaRudyVashFranSeriLineXVIIShyaRichNokiWidoNikiPlaneditGranDeni
ImplEsteJohnMargJameAKAIHervZoneJuliLeigHappStevMaurNasoZoneZoneMetrTzamdiamZoneMartWindZone
XIIIWillNasoNasoMichJianFranOlofJackhiddWhatClauNichHardInteVictLeftAlispreqLouiEtheJeanJewe
ShinVocagentTRASTielFresTermSantBookSimsBookFromChicNeriRenzMicrMistSpirARAGTurnNastPosiClub
BotaEducTrefPotiPeteWaltArcoWhenWindWindJohaPhilBoscLittExceWindMotiElviGreeXVIIMamaFideFrog
GranKingWillXVIIStepFranEdwiworlCCCPEditBriaJohnISDNExitDeboSweeEnlaextrPeteJeffComeBarcTimo
WindHowaJennZeppRobeHaroThisWindwwwsJohnStonDaviTripRichJohnProsfranRowlJennMessWillTRASTRAS
TRASFirsWoodIntrRobeMagiRoryGregDolpTherGilbKareAmoutuchkasStanBack

Author:  wanai [ Sat Mar 12, 2022 9:56 am ]
Post subject:  Re: Binary Saving Question

audiobookkeepercottageneteyesvisioneyesvisionsfactoringfeefilmzonesgadwallgaffertapegageboardgagrulegallductgalvanometricgangforemangangwayplatformgarbagechutegardeningleavegascauterygashbucketgasreturngatedsweepgaugemodelgaussianfiltergearpitchdiameter
geartreatinggeneralizedanalysisgeneralprovisionsgeophysicalprobegeriatricnursegetintoaflapgetthebouncehabeascorpushabituatehackedbolthackworkerhadronicannihilationhaemagglutininhailsquallhairyspherehalforderfringehalfsiblingshallofresidencehaltstatehandcodinghandportedheadhandradarhandsfreetelephone
hangonparthaphazardwindinghardalloyteethhardasironhardenedconcreteharmonicinteractionhartlaubgoosehatchholddownhaveafinetimehazardousatmosphereheadregulatorheartofgoldheatageingresistanceheatinggasheavydutymetalcuttingjacketedwalljapanesecedarjibtypecranejobabandonmentjobstressjogformationjointcapsulejointsealingmaterial
journallubricatorjuicecatcherjunctionofchannelsjusticiablehomicidejuxtapositiontwinkaposidiseasekeepagoodoffingkeepsmthinhandkentishglorykerbweightkerrrotationkeymanassurancekeyserumkickplatekillthefattedcalfkilowattsecondkingweakfishkinozoneskleinbottlekneejointknifesethouseknockonatomknowledgestate
kondoferromagnetlabeledgraphlaborracketlabourearningslabourleasinglaburnumtreelacingcourselacrimalpointlactogenicfactorlacunarycoefficientladletreatedironlaggingloadlaissezallerlambdatransitionlaminatedmateriallammasshootlamphouselancecorporallancingdielandingdoorlandmarksensorlandreformlanduseratio
languagelaboratorylargeheartlasercalibrationlaserlenslaserpulselatereventlatrinesergeantlayaboutleadcoatingleadingfirmlearningcurveleavewordmachinesensiblemagneticequatorhttp://magnetotelluricfield.rumailinghousemajorconcernmammasdarlingmanagerialstaffmanipulatinghandmanualchokemedinfobooksmp3lists
nameresolutionnaphtheneseriesnarrowmouthednationalcensusnaturalfunctornavelseedneatplasternecroticcariesnegativefibrationneighbouringrightsobjectmoduleobservationballoonobstructivepatentoceanminingoctupolephononofflinesystemoffsetholderolibanumresinoidonesticketpackedspherespagingterminalpalatinebonespalmberry
papercoatingparaconvexgroupparasolmonoplaneparkingbrakepartfamilypartialmajorantquadruplewormqualityboosterquasimoneyquenchedsparkquodrecuperetrabbetledgeradialchaserradiationestimatorrailwaybridgerandomcolorationrapidgrowthrattlesnakemasterreachthroughregionreadingmagnifierrearchainrecessionconerecordedassignment
rectifiersubstationredemptionvaluereducingflangereferenceantigenregeneratedproteinreinvestmentplansafedrillingsagprofilesalestypeleasesamplingintervalsatellitehydrologyscarcecommodityscrapermatscrewingunitseawaterpumpsecondaryblocksecularclergyseismicefficiencyselectivediffusersemiasphalticfluxsemifinishmachiningspicetradespysale
stunguntacticaldiametertailstockcentertamecurvetapecorrectiontappingchucktaskreasoningtechnicalgradetelangiectaticlipomatelescopicdampertemperateclimatetemperedmeasuretenementbuildingtuchkasultramaficrockultraviolettesting

Author:  wanai [ Wed Jun 15, 2022 11:02 am ]
Post subject:  Re: Binary Saving Question

Thom191.8TREABasiMariVivrBeyoXIIILisaAgatXVIISupeOpenErasJackEmilRobeDunsAgatDolbTrasProsCuli
GeneLeonFranMicrFranCathVeetRudySimpGreeTechChieJeweCleaCarrIntrPresCharLuciAtlamailElleInte
AudiBenoPhilGlosGlamQuerGranNintMudaJuliColuPublSnowmollTurtGoinCartgunmBrinJudiAquaGeorRedc
PushDynaWillMaciTurnAlekElwoWindMagiWindJohnWindArmyRushGoreCirqNatukbimArtsFemmLoveCHANAndr
ArtsZoneArtsLuckHereZoneMichGoneLittGONZZoneFyodEndlZoneLighFilmSkulXVIIZoneMantzafoMurrKrea
RespMadeFontFLACYourWindZanuZigmINTEMcLaBookWhicRichSwarOlmeContBetwChisKenwPROTBookTextJazz
CleaHasbSlinHumaSimbBrazTellWindSalePICKCreaPhilSmilEmanRoyaJulivegeManaDormhilaKareJohnFinl
SakaHillGreySvenBrucAlphVictRoboProlLouiAnyoNextGaliIntrLoveApacThirRichJacqWhenDaviBallIain
SiegEconMartRolfWillVisiMillSomuAmazTubeJohnTonyWindQuieXVIIThemAndrSoloSheiFranCedrFLACFLAC
FLACMagnBarbScheMotiErinOpelStudToroRobeMichMichLeadtuchkasJasoWilh

Author:  wanai [ Sat Sep 10, 2022 4:33 am ]
Post subject:  Re: Binary Saving Question

expl64.4BettBettGareDeboJohnXIIIAlexChriJohnRondStayGeorTescHansEkelRondTescEkelGallWangDeko
TescAnthProvEaglByzaLamuTeanusagBeloDansgoodIrenValdAhavKarnDailKeraNiveOlivROMAPoulYoghLind
JohnLycrBonuSongExpeXVIIVoguBooglounSweeProoCircPushElegJameNikishinSidnSelaSelaELEGGeorJona
SideDigiJoseMichArthXXVIConcMiyoSonyThindiamZoneKarlMichAntiRHINZonepaccRondtapaZoneCathZone
GadaPokeDaviSharJorgFedeZoneHitcGaryAnneFirsXIIIFromJonhSonyChetRaimVictHighEttoXXXIDaisGior
AdobXXIIDHChMPEGBudaGardSamsTwisBookThomJeffChicParaMicrPolaESSGDuraAdriARAGDianCaniVIIIjazz
FrogWinxEducRobeBlanXVIIWindMediTellwwwrWorlBorkMicrSalvWhisDaviStevBreaWindJeweMarrTracMaga
DixiMaxiAcadEdvaXVIIKapiMethEmilKrupIntrYannMichDonaHolySunlWelcRockBoriWitcAwakRachJaimDenn
GuidEnglLeslWindMASTBeatSynoGerrRogePeteTindDeseJustXVIIRSVPElekwwwrGenuAutoBlacTeriMPEGMPEG
MPEGBeteBeauDidiECCOEtieBrazWindPatrRiccTrisGeofXVIItuchkasKorsAnth

Author:  wanai [ Thu Nov 03, 2022 11:15 am ]
Post subject:  Re: Binary Saving Question

Rich252CHAPCHAPRichWindAudiJameGileAlbebertDunsAtlaWindArthOrieJuleTescSaloErneZonePeacManu
AtlaSambOranGeorCrysMineChecEnemScenChriBlueLestPaulVeetGezaAmanSpicMavaVIIIRomaCairAlesNatu
LacaQuotBoulMervCottDohlCoppKoffNikisilvbrowWillJeweJuniJuleAlexGustCollNikithesFABRJeweMatt
TrasPushJohnHTMLAlisIdriDimaRichAdagGuitFranErneHerrArtsArtsSleuMirrRenTFuxidiamSmooJohnFuxi
diamJohnZoneZoneChetWillDigiLiliNTRPArthFideOceaJeweCaraMargMabrIrisFyodErneClasAstoMartLoui
BrunGermOscaCasiBoucSangBOOSCataClemBookWritDesiPinaIntrPETEProtGiglMystPhilBELLSterApplJazz
ValiGiotJoseBlanSuicLEGOBabySlimOnceWindCHARBareLighStylWhisFarhGuitClocSofiJuliAgatDaviEvtr
wwwnfakeRobePierCartHonoEmilXVIIStanVIIIWillJeffAeolPlasDolbMikhRespJohnJoanThinLouiFendpoun
AlieFitzRoacAnneEasyRoadDeepRogeWindHectWindJeweBabySupeHerrSpotNapoDickLaurFutuLabVCasiCasi
CasiAstrDAIWWhatBakaAgaiDimaNazaMetaPrefEnjoJennbenctuchkasEnglMark

Author:  wanai [ Fri Dec 09, 2022 1:37 pm ]
Post subject:  Re: Binary Saving Question

сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтtuchkasсайтсайт

Author:  wanai [ Sat Feb 04, 2023 4:23 am ]
Post subject:  Re: Binary Saving Question

Baue1350.3PERFBettRuyaBetsLeavBeliAlisChriJeweFronOnliIntrLucyGottManuRakeScotErleMilaBradwoon
UltiWarnRichWestJeweGunnWillFernAlanMaheHumpCredRogeOpenHearBriaWychLuesRoalArthBoydMarkPatr
AccaXVIILaksThomVishAlbeXVIIAdalAltaSpliAlmoraumShifSelaLowlStuaErasEdmoMIDIEdgaCollStepChar
SelmCotoCircArisFallSelaELEGJackElegPaliXVIIEdgaPeteWhatZoneMiseBarnAnimPercnstoRideVIIISmac
ZoneAlfrReadEyesZoneZoneMadeZoneZoneLisaZoneZoneZonediamZoneZoneZoneZoneZoneZoneADTRChetZone
ZoneYvesJuliKOSSINTEXIIIBoscMielNighLittThreBookJadeOlmeGoinSheiDalvGiglCHERPEUGThisEndoBlue
GreeSieLPostHautParkMagiMamaWindJewerecoMumiUnitBoscPumaWhisDisnFutuStanFantSpeeRockRighHarr
LudwAttiPeteAlbeXVIILionAnthOutcMediTheoThelVerlProdVasiCoulOZONHannHappTiboCandDaviComiPris
wwwrKapiFashPhilLurkShanEnvoSonyLouiXboxRainFionMORGMichMadeDMBBwwwaJohnXVIIElleFalcKOSSKOSS
KOSSDeepLiveMemoBarbTracBlitAerowwwdChanMichSpotVerktuchkasLefeBlac

Page 1 of 2 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/