Help Loading Objects
#1

Hey when i read from a file i get this printed in my console:


19295 7538.399900 -2031.000000 332.500000 0.000000 0.000000 0.000000
Objectid X Y Z ROT:X ROT:Y ROT:Z


i need help to read this step by step

i use filemanager
Reply
#2

I'd suggest using sscanf. It's really easy to read line by line with that.

I assume you have the reading part done already, so you have the current line in an array inside a loop or so.

With sscanf you can extract the values by their format and load them into variables:

PHP код:
new modelFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rz;
if(
sscanf(text"iffffff"modelxyzrxryrz))
{
    
// Invalid line
}
else
{
    
// Line was parsed, you can now use model, x, y, z, rx, ry, rz to create the object

The "iffffff" part in the sscanf function tells it to read one integer (i) and 6 float values (f), followed by the variables to write the values to.
"text" would be the array with the current line you want to parse.
Reply
#3

But i read it like this from the file

Код:
19295 7538.399900 -2031.000000 332.500000 0.000000 0.000000 0.000000
How can i read it without the spaces like

Код:
CreateDynamicObject(19295,7538.399900, -2031.000000, 332.500000, 0.000000, 0.000000 ,0.000000);
Reply
#4

Quote:
Originally Posted by theralio
Посмотреть сообщение
But i read it like this from the file

Код:
19295 7538.399900 -2031.000000 332.500000 0.000000 0.000000 0.000000
How can i read it without the spaces like

Код:
CreateDynamicObject(19295,7538.399900, -2031.000000, 332.500000, 0.000000, 0.000000 ,0.000000);
Oh I see.

You can do it with sscanf too:

PHP код:
sscanf(text"p<,();>'CreateDynamicObject'iffffff"modelxyzrxryrz); 
p<,();> will ignore the signs , ( ) ; (so all these signs are accepted as delimiters).

The 'CreateDynamicObject' part will require it to be part of the line (at the start).
Reply
#5

ok thx it works
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)