Page 1 of 1

Problems with ReplaceString

Posted: Sun Apr 11, 2004 9:43 am
by Switchblade
Hi,

Ive got some Problems with the command replaceString.

Ive got one .con file (its like .txt) where i want to replace the Y Value.
XYZ is set each time in the lines Object.absolutePosition

Code: Select all

rem ***  ***
rem
Object.create asteroid
Object.absolutePosition 1024/100/1024
Object.Rotation 243.611/0/0
rem
rem ***  ***
rem
Object.create spacerock1
Object.absolutePosition 1241.91/100/1230.2
Object.Rotation 280.8/0/0
rem
rem ***  ***
rem
Object.create spacerock4
Object.absolutePosition 1293.92/100/892.582
Object.Rotation 283.942/0/0
rem
rem ***  ***
rem
Object.create asteroid
Object.absolutePosition 739.968/141.657/1121.84
Object.Rotation 243.182/0/0
rem
rem ***  ***
rem
Object.create asteroid
Object.absolutePosition 805.999/100/814.846
Object.Rotation 292.028/0/0
rem
rem ***  ***
rem
Object.create asteroid
Object.absolutePosition 934.951/100/1353.39
Object.Rotation 120.586/0/0
My problem is, that i dont know how to set the parameters for the command ReplaceString.
You see, that each times "Object.absolutePosition X/Y/Z" not has always the same Y value. So how can i write the command line ?

Code: Select all

If ReadFile(1, (file$))    ; file$ is the openfilerequester variable       
          ReplaceString("Object.absolutePosition 1024/100/1024", StringY$, "100" ,1 ,1) 
            
          CloseFile(1) 
                      
        EndIf 
i really dont know how to fix that , its urgent ;)
thx

Posted: Sun Apr 11, 2004 10:10 am
by Comtois

Code: Select all

t.s = "Object.absolutePosition 1024/234.45/1024"
Y.s=StringField(t,2, "/") 

Debug t
t=ReplaceString(t, Y, "100" ,1 ,1)
Debug t

Posted: Sun Apr 11, 2004 10:27 am
by Froggerprogger
Your example-code handles the ReplaceString-command in a wrong way.
You simply replace the StringY$ by "100" inside the fixed string "Object.absolutePosition 1024/100/1024"
This has nothing to do with the lines in the file.
You would have to handle the complete file as a string to replace text in. But this string would perhaps reach the 64k-limit.
Further you would replace all the y-values that are inside the specified xyz-combination and it's not a fast & elegant way to do this several times per second for storing the actual objectdata.

You should read in the file into a linked list (when the number of objects is variable) at the program start and then do all changes onto the list.
The list could look like:

Code: Select all

Structure MyObjectData
  type.s
  posX.f
  posY.f
  posZ.f
  rotX.f
  rotY.f
  rotZ.f
EndStructure

NewList objects.MyObjectData()
Then write a routine to read in the data and another one to stream it into a blank file to save the changes.

Posted: Sun Apr 11, 2004 7:47 pm
by Switchblade
how ?

Posted: Mon Apr 12, 2004 12:13 pm
by Froggerprogger
Something like this:

[pseudocode]

Code: Select all

NewList objects.MyObjectData()
If OpenFile()
  While Eof() = #False
    line = Readline()
    If Stringfield(line, 1, " ") = "Object.create"
      AddElement(objects())
      objects()\type = StringField(line, 2, " ")
      line = ReadLine()
      objects()\posX = ValF(StringField(StringField(line, 2, " "), 1, "\")
      ;... use Stringfield() with " " and "\" to get all the data
      line = ReadLine()
      ;... same for rotation
    Endif
  Wend
EndIf
[/pseudocode]

Hope that helps you getting started.