Jump to content
Sign in to follow this  
Linker Split

Export text via script to a .txt file

Recommended Posts

I think I've figured out a workaround...

Do you know if, everytime the server restarts, the saveProfileNameSpace overwrites only the selected variables, or erases the whole .vars file and writes inside only the variables we are saving?

Don't know if you got the point of my question

#EDIT

It seems that it erases te content of the .vars file

Edited by Linker Split

Share this post


Link to post
Share on other sites

In your if statement "_checkCarState" shouldn't be in quotes, just: _checkCarState

And I'm not quite certain that the .vars gets cleared on restart, Cuel seems to have remember a bug or something similar, but I'm unaware of such, but if that bug/whatever did exist, it was before my time of understanding profileNamespace and get/setVariable, so hopefully with some quick testing of that we could decide if most of this was for nothing or not :).

Share this post


Link to post
Share on other sites

Yeah, it defi erases the content and then writes only the variables saved via saveProfileNameSpace.... anyway it's not a big problem.

Let's say that for the first instance I save the position of the car as positioncar1:

_pos = getPosASL _vehicle1;
profileNameSpace setVariable ["PositionCar1",_pos];

to recall this variable, I should use:

_pos = profileNameSpace getVariable "PositionCar1";
_vehicle1 setPos _pos;

if I want to use the diag_log to read in the RPT the _pos, how would I write the code?

diag_log format["%1",_pos];

or

_string = str(_pos);
diag_log format["%1",_string];

Share this post


Link to post
Share on other sites

The first block is correct for using format and diag_log.

Share this post


Link to post
Share on other sites

Still when I setPosASL to _pos:

_pos = profileNameSpace getVariable "PositionCar1";
_vehicle1 setPosASL _pos;

It returns me <null> as position...

This thing is gonna make me mad cause in my server.vars file there is

class Item2
{
	name = "positioncar1";
	class data
	{
		class type
		{
			type[] = {"ARRAY"};
		};
		class value
		{
			items = 3;
			class Item0
			{
				class data
				{
					class type
					{
						type[] = {"SCALAR"};
					};
					value = 8407.656;
				};
			};
			class Item1
			{
				class data
				{
					class type
					{
						type[] = {"SCALAR"};
					};
					value = 5079.379;
				};
			};
			class Item2
			{
				class data
				{
					class type
					{
						type[] = {"SCALAR"};
					};
					value = 158.74274;
				};
			};
		};
	};
	readOnly = 0;
};

#EDIT

It returns me any

Edited by Linker Split

Share this post


Link to post
Share on other sites

When you run this code is it within an if (isServer) statement?

Share this post


Link to post
Share on other sites
When you run this code is it within an if (isServer) statement?

nope, I din't check if isServer is true.

But I'm running this on a server (connecting with my PC via remote desktop)

Share this post


Link to post
Share on other sites

Ok, let's start over.

I have this server.vars file:

[size=1]class ProfileVariables
{
items = 4;
slots = 15;
class Item0
{
	name = "dzfirstinstance";
	class data
	{
		class type
		{
			type[] = {"SCALAR"};
		};
		value = 1.0;
	};
	readOnly = 0;
};
class Item1
{
	name = "checkcarstate";
	class data
	{
		class type
		{
			type[] = {"BOOL"};
		};
		value = 1;
	};
	readOnly = 0;
};
class Item2
{
	name = "positioncar1";
	class data
	{
		class type
		{
			type[] = {"ARRAY"};
		};
		class value
		{
			items = 3;
			class Item0
			{
				class data
				{
					class type
					{
						type[] = {"SCALAR"};
					};
					value = 8407.656;
				};
			};
			class Item1
			{
				class data
				{
					class type
					{
						type[] = {"SCALAR"};
					};
					value = 5079.379;
				};
			};
			class Item2
			{
				class data
				{
					class type
					{
						type[] = {"SCALAR"};
					};
					value = 158.74274;
				};
			};
		};
	};
	readOnly = 0;
};
.....
.....
.....[/size]

I've saved dzfirstinstance in this way:

[size=1]_t = 1;
profileNameSpace setVariable ["dzfirstinstance",_t];
saveProfileNameSpace;[/size]

I've saved checkcarstate in this way:

[size=1]
checkCarState = true;
profileNameSpace setVariable ["checkCarState",true];
saveProfileNameSpace;
[/size]

I've saved positionCar1 in this way:

[size=1]_vehicle1 = createVehicle ["car", [8408, 5080, 2.5], [], 0, "CAN_COLLIDE"];
_pos = getPosASL _vehicle1;
profileNameSpace setVariable ["PositionCar1",_pos];
saveProfileNameSpace;[/size]

Can you, or somebody, tell me, case per case, how to recall the values from those variables?

1) is SCALAR (how to getVariable and how to diag_log);

2) is BOOL (how to getVariable and how to diag_log);

3) is ARRAY with inside 3 SCALAR values (how to getVariable and how to diag_log);

If you can answer these 3 questions, I'll send you a pack of good Italian wine :biggrin_o: :biggrin_o: :biggrin_o:

Edited by Linker Split

Share this post


Link to post
Share on other sites

I don't know why it won't work with the following, unless I'm just a horse with its blinders on:

_someScalarVar = profileNamespace getVariable ["dzfirstinstance",nil];
_someBoolVar = profileNamespace getVariable ["checkCarState",false];
_someArrayVar = profileNamespace getVariable ["PositionCar1",[0,0,0]];

Share this post


Link to post
Share on other sites
I don't know why it won't work with the following, unless I'm just a horse with its blinders on:

_someScalarVar = profileNamespace getVariable ["dzfirstinstance",nil];
_someBoolVar = profileNamespace getVariable ["checkCarState",false];
_someArrayVar = profileNamespace getVariable ["PositionCar1",[0,0,0]];

Man, I'll try these ones tomorrow but I'm afraid they won't work cause I remember (in the many tests I've done since now :D) that they didn't work...

anyway... if it won't work, I'll post the entire source script lol

Share this post


Link to post
Share on other sites
I don't know why it won't work with the following, unless I'm just a horse with its blinders on:

_someScalarVar = profileNamespace getVariable ["dzfirstinstance",nil];
_someBoolVar = profileNamespace getVariable ["checkCarState",false];
_someArrayVar = profileNamespace getVariable ["PositionCar1",[0,0,0]];

Ok, so it seems that even if profile.vars exists after the first run of the server, and it got all the variables inside it, everytime the server restarts it doesn't see the variables inside it... should I try to assign variables to the objects, instead of to profileNameSpace?

Let's try this?

Share this post


Link to post
Share on other sites

If you assign it to the objects it will throw persistence out the window because as soon as that object is deleted in anyway (mission restart/server restart) those variables won't exist at all. I don't know why it's not getting the variables out of the server's profile vars file, and at this point I'm out of ideas. As I said earlier, it's either a bug, or I have blinders on and I'm not seeing the issue...

EDIT: Found the feedback tracker ticket I think Cuel was referring to, but it's labeled as fixed

Edited by JShock

Share this post


Link to post
Share on other sites

What about the first post I wrote about passing variable to a .txt file?

is it too much coding?

Share this post


Link to post
Share on other sites

I actually don't know how to write to a .txt in Arma scripting, I know how to access information already there, but not actually write to it. And in my short search, it seems that previous threads with a similar topic end up getting referred back to profileNamespace.

This is the one I was looking at specifically:

http://forums.bistudio.com/showthread.php?153805-Write-in-a-file-with-a-script

EDIT: Another couple threads, with some other options, one being extensions (another thing I have no clue about).

http://forums.bistudio.com/showthread.php?171096-How-to-make-a-script-write-to-a-file

http://forums.bistudio.com/showthread.php?151762-Write-to-a-text-file-other-than-the-RPT

Edited by JShock

Share this post


Link to post
Share on other sites

mmm... I'm thinking about copyToClipboard and LoadFromClipboard commands along with parsetext etc...

Share this post


Link to post
Share on other sites

Server profileNamespace is saving fine over restarts on my machine:

profileNamespace setVariable ["VAR", "this_is_some_text"];

Then after a restart:

diag_log format ["SERVER PROFILENAMESPACE VAR: %1",profileNamespace getVariable "VAR"];

returns:

"SERVER PROFILENAMESPACE VAR: this_is_some_text"

You're probably overwriting the profile when you restart it if it's not working for you.

Share this post


Link to post
Share on other sites

You're probably overwriting the profile when you restart it if it's not working for you.

Since I'm scripting for a MOD that got a looooot of scripts, you are suggesting me to go and check for what?

I don't see any commands that deletes everything from the .vars profile... basically you are saying that a .vars got erased and overwritten instead of adding variables to the file?

Share this post


Link to post
Share on other sites

I'm not sure why it's not working for you and I don't have any suggestions for things to check unfortunately. I would assume that since it does work for some and not others, then it's most likely something to do with the profile.

Share this post


Link to post
Share on other sites

Well just for shits try using if (isServer) everywhere to ensure it isn't a locality issue, but then I'm out of ideas :(.

Share this post


Link to post
Share on other sites
I'm not sure why it's not working for you and I don't have any suggestions for things to check unfortunately. I would assume that since it does work for some and not others, then it's most likely something to do with the profile.

problem is that when writig variables via setVriable, they got written in my .vars file.

After shuting down the server, the .vars is still there with all the variables written inside (correctly written btw).

So when I restart the server, and use the getVariable, it simply returns "any", "null".... wtf ahahha

Well just for shits try using if (isServer) everywhere to ensure it isn't a locality issue, but then I'm out of ideas :(.

I'm going to use the

if (!isServer) exitWith {diag_log "IS NOT SERVER!!!!!"};

---------- Post added at 21:04 ---------- Previous post was at 20:31 ----------

I've put:

if (!isServer) exitWith {diag_log "SERVER IS NOT SERVER!!!!!!!!!"};
if (isDedicated) exitWith {diag_log "DEDICATED IS NOT SERVER!!!!!!!!!"};

it pops up: "DEDICATED IS NOT SERVER!!!!!!!!!"

What it means?

Share this post


Link to post
Share on other sites

It's right, just rename them to be less confusing:

if (!isServer) exitWith {diag_log "THIS IS NOT A SERVER!!!!!!!!!"};

if (isDedicated) exitWith {diag_log "THIS IS DEDICATED, NOT LOCALLY HOSTED!!!!!!!!!"};

The dedicated check is checking for true, not false like the first statement (unless you meant !isDedicated).

Share this post


Link to post
Share on other sites
It's right, just rename them to be less confusing:

The dedicated check is checking for true, not false like the first statement (unless you meant !isDedicated).

yeah you are right, I was just checking for diag_log :D

Anyway... seems that it's all ok, also because as said I'm running on a server (and I connect to it via remote desktop btw)

So I really don't know what the problem is... :(

Share this post


Link to post
Share on other sites

Guys I think that we have figured out how to get the variables ingame back after restart.

one script question:

if I want to assign a value to a variable in SQF, but it's dinamically changing, can I use this syntax:

format["_xPos%1",_nmr] = ((getPosASL _car) select 0);

In this way I can save _xPos1, _xPos2,_xPos3 and so on....

Share this post


Link to post
Share on other sites
if I want to assign a value to a variable in SQF, but it's dinamically changing, can I use this syntax:

No that syntax will not work. You can do something similar for global variables.

missionNamespace setVariable [ format [ "xPos%1", _nmr ], ((getPosASL _car) select 0) ];

xPos1 will now equal the position of _car

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×