I'm new to scripting and i've got a difficulty.
Tell me how to write text to a file and then read it.
With examples please.
Thanks.
begin DHM_Alchemy_Table_Mainshort stateshort buttonshort addingr ;add ingredients or remove them?;really longslong count ;item countlong objtype ;object typelong l1 ;temp/junk;stringslong filename ;not necessary, but makes it easier to change if you wantlong objid ;object ID (for inventory items);refslong destref ;reference for who/whatever gets the ingredients at the endlong giveref ;reference for who/whatever has the items to startlong invref ;inventory item referencefloat f1 ;junk varif ( GetDisabled ) if ( GetJournalIndex "HT_EddieTable" >= 100 ) enable endifelseif ( GetJournalIndex "HT_EddieTable" < 70 ) disableendifif ( MenuMode ) returnelseif ( OnActivate ) if ( state == 0 ) MessageBox "What do you want to do?" "Open container" "Add all ingredients" "Remove all ingredients" "Cancel" set state to 1 endifelseif ( state == 1 ) set button to GetButtonPressed if ( button == -1 ) return elseif ( button == 0 ) ;open normally activate set state to 0 elseif ( button == 1 ) ;add all set addingr to 1 set state to 2 elseif ( button == 2 ) ;remove all set addingr to 0 set state to 2 else ;cancel set state to 0 endif returnendifif ( state < 2 ) returnendififx ( addingr ) setx destref to xGetRef "container_ID" setx giveref to xGetRef "player"else setx destref to xGetRef "player" setx giveref to xGetRef "container_ID"endifsetx filename to xStringBuild "DHMAlchemyTable" ;sets the filename variable to this stringxFileRewind filename ; - change to whatever you want, but no spaces!;next bit is finding out what ingredients have to be moved;and writing it to a file, so we can move them all at once;in the next blocksetx objid count objtype l1 f1 l1 invref to giveref->xContentList 0 ;gets the first item in inventorywhilex ( objid ) set l1 to ( objtype - 1380404809 ) ;ingredient ifx ( l1 ) ;it's not an ingredient else xFileWriteString filename objid xFileWriteLong filename count endif ifx ( invref ) setx objid count objtype l1 f1 l1 invref to giveref->xContentList invref ;move on to the next item else set objid to 0 ;exit loop endifendwhilexFileWriteString filename "null" ;in case there aren't any ingredients in inventory;now we read the file back and do the actual adding and removing;xStringCompare will return 0 if the strings are the same;so use this to check when we've got to the end - otherwise weird things can happen!xFileRewind filenamesetx objid to xFileReadString filenamesetx l1 count to xFileReadLong filename 1setx l1 to xStringCompare objid "null" ;check here too, in case there weren't anywhilex ( l1 ) giveref->xRemoveItem objid count destref->xAddItem objid count setx objid to xFileReadString filename setx l1 count to xFileReadLong filename 1 setx l1 to xStringCompare objid "null"endwhileset state to 0end
ifx ( run ) setx filename to xStringBuild "BOHcoords" xFileRewind filename setx junk pX pY pZ pA to xFileReadLong filename 4 setx pcCell to xFileReadString filename player->xPositionCell pX pY pZ pA pcCell set run to 0endif
xFileWriteText "|MGEpipe" "Td%"xFileWriteString "|MGEpipe" "data files\splash\Splash_Bonelord.tga"