Problems with ReplaceString

Just starting out? Need help? Post your questions and find answers here.
Switchblade
User
User
Posts: 17
Joined: Mon Apr 05, 2004 1:27 am
Contact:

Problems with ReplaceString

Post 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
AMD 2800+ , 1024DDR 400, Nvidia FX 5600 Pro 256DDR, Hersules Game Theater 7.1
User avatar
Comtois
Addict
Addict
Posts: 1431
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post 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
Please correct my english
http://purebasic.developpez.com/
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post 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.
%1>>1+1*1/1-1!1|1&1<<$1=1
Switchblade
User
User
Posts: 17
Joined: Mon Apr 05, 2004 1:27 am
Contact:

Post by Switchblade »

how ?
AMD 2800+ , 1024DDR 400, Nvidia FX 5600 Pro 256DDR, Hersules Game Theater 7.1
Froggerprogger
Enthusiast
Enthusiast
Posts: 423
Joined: Fri Apr 25, 2003 5:22 pm
Contact:

Post 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.
%1>>1+1*1/1-1!1|1&1<<$1=1
Post Reply