Home   Help Search Login Register  

Author Topic: Properties for objects  (Read 4857 times)

0 Members and 1 Guest are viewing this topic.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #30 on: 12 May 2005, 10:11:27 »
Right, so that means you don't need the "GENB_Properties", just the 'GENB_Properies = []' argument. That could work fine

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #31 on: 05 Jul 2005, 02:42:04 »
OK, I have at last gotten around to incorporating HateR's and Gen Barron's suggestions

SetProperty v1.1
GetProperty v1.1

As of v1.1 the two functions can take an optional extra argument. This is a string, and is the name of the custom array you wish to store the properties in.

The custom array is created the first time either of the functions is run, just like the default array which is still used if you don't specify the extra parameter.

The default array is now named 'FRG_Properties' in accordance with Ofpec rules.

If you substitute the two old functions with these two new ones, they are completely backwards compatible. No additional setting up is required.

Thanks Gen and HateR

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Properties for objects
« Reply #32 on: 06 Jul 2005, 10:07:43 »
Nice. This will be seeing some use. :)
HANDSIGNALS COMMAND SYSTEM-- A realistic squad-control modification for OFP
kexp.org-- The best radio station in the world, right here at home! Listen to John Richards!

DBR_ONIX

  • Guest
Re:Properties for objects
« Reply #33 on: 07 Jul 2005, 16:20:13 »
I had a try with these functions (V1, not the new version I think)
But, I couldn't get them to work ???
Basicly, I wanted to use them for a money system on an RPG mission.
So at the start (Tried init.sqs, and then renaming it to start and running it via radio trigger to see if running it before screwed it up, for some strange reason..), I run the following code :
Code: [Select]
;General scripty stuff
GetProperty = preprocessFile "getproperty.sqf"
SetProperty = preprocessFile "setproperty.sqf"

; Set up starting stuff
[aP1,"BankMoney",200] call SetProperty
[aP2,"BankMoney","200"] call SetProperty

[ap1,"PocketMoney",10] call SetProperty
[ap2,"PocketMoney",10] call SetProperty

; Debug
player sidechat FORMAT ["Debug - ap1 Bank : %1 :: ap2 Bank : %2 ::: ap1 Pocket : %3 :: ap2 Pocket : %4",[ap1,"BankMoney"] call GetProperty,[ap2,"BankMoney"] call GetProperty,[ap1,"PocketMoney"] call GetProperty,[ap2,"Pocket"] call GetProperty]

player sidechat "blah"

But, it never got to that sidechats..

I'll try the new version when I get back from holdiay (leaving tomorrow). But if I could get this working, it'd make the misison so much easier to code.
Instead of having a buy script for each player, and addng them in grouped-to-player triggers (Horrible). I could have dialouges (Need someone who can use dialouges, or learn them by self.. noo :P), which run a buy script,
And check _this select 0 (not sure if this works with dialouges, but just the general idea) has enough money
If so, remove the cost from the varible (from gerproperty), and shove it back via setProperty.
This means there could be a single buy script, with a ?(_action=="gun"):goto "buyGun" for each thing (Cars, guns, food etc), which takes the money, and does appropriate action (create gun/ammo in weaponHolder thing, for example)
But, this all hinges on getting these functions to work :P

Is there something I'm doing wrong in that code?

Thanks :)
- Ben

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #34 on: 09 Jul 2005, 00:58:03 »
Hm, don't know why the sidechats aren't working.

However, I replaced the sidechat format... with a hint format etc and it all came out fine. Except for "pocket" which was undefined, but I guess you changed that for testing purposes.

Problem solved ;)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Properties for objects
« Reply #35 on: 09 Jul 2005, 14:11:00 »
Sweetness :)

This stuff is now quite essential part of some scripts/systems in FWW2 Mod... :P
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #36 on: 10 Jul 2005, 01:17:42 »
It makes me glad to hear that ;D

Bluelikeu

  • Guest
Re:Properties for objects
« Reply #37 on: 13 Jul 2005, 01:45:20 »
Just as a side question: Where is Chad and his infamous compiler? 'Been waiting for quite some time.

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #38 on: 17 Jul 2005, 10:09:31 »
Bad news. I've been putting the system through it's paces, so to speak, by taking a large number of functions (in string form, loadfile'd) and adding them into a single array via setproperty. Everything goes according to plan until the fourth function or so is loaded, after which operation flashpoint crashes to desktop whenever you try and add another.

So there is obviously an upper limit on the total amount of data you can store in an array, which is confusing since up until now I'd thought that arrays in operation flashpoint functioned a lot like lists- meaning that they annex memory wherever there is a chunk of the correct size, regardless of it's position on the stack. The system works fine if I create a new array and start filling that one up.

Any ideas on how to get around this are welcome. I remember a thread a while back where someone mentioned troubles with array sizes.... i didnt bother to read it at the time, unfortunately. If anyone's run into this problem, let me know. Thanks

UNN

  • Guest
Re:Properties for objects
« Reply #39 on: 17 Jul 2005, 18:54:42 »
Hi,

It's not array's that have the limit your hitting but the Format command:

Code: [Select]
if ( format["%1", FRG_Properties] == "scalar bool array string 0xfcffffef") then {
      _userPropertyArray = [];

If you have to many characters in your array and you try and format it to a string, it will crash.

You can use something like this to get round the problem:

Code: [Select]
_ARRAY_INITIALISED={_T=True ; If (Count UKF_WMIKARRAY>=0) Then {_T=False} ; !_T};

If !(Call _ARRAY_INITIALISED) Then
   {
   UKF_WMIKARRAY=[];
   };

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #40 on: 18 Jul 2005, 01:23:41 »
Oh, i see!

In fact, i kept running into the problem where I had the line 'hint format' etc etc, in some other code .... but i thought it was the hinting, not the formatting, that was the trouble. It would have never even occurred to me to check for 'format...'. Thanks a whole bunch, UNN, saved my skin ;D

That workaround is pretty fantastic as well.... i assume the 'call' command supresses the error message that comes from 'count UKF_WMIKARRAY>=0' when UKF_WMIKARRAY is uninitialised... very tricky. i take it this is a problem that UK forces ran into as well. then?

Cheers



UNN

  • Guest
Re:Properties for objects
« Reply #41 on: 18 Jul 2005, 02:43:28 »
Quote
It would have never even occurred to me to check for 'format...'.

It's probably the same with Hint to. Or at least, just the way ofp handles strings in both cases?

Quote
That workaround is pretty fantastic as well

Thank BN880 from the COC for that :) It is quite handy, you can even use it to surpress script not found errors, and detect some other variable types. Does not seem to work with Object related commands though :(

Quote
i take it this is a problem that UK forces ran into as well. then?

It's an old problem, I just happend to have those scripts at hand. Before BN880's function, you had to have a boolean along with the array, and check that with Format, rather than the array.

It should be faster than comparing a string with the format command, but not as fast as just checking a single boolean. Depends how many elements you have in your array I guess.

You could change it to this, and derive your booleans name from the user defined array name you get as a parameter:

Code: [Select]
_ARRAY_INITIALISED={_T=True ; If UKF_WMIKARRAY_B Then {UKF_WMIKARRAY_B=True ; _T=False} ; !_T};

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #42 on: 18 Jul 2005, 08:30:13 »
Version 1.15
(same place)

Thanks UNN. The conditional statement

Code: [Select]
_ARRAY_INITIALISED={_T=True ; If (Count UKF_WMIKARRAY>=0) Then {_T=False} ; !_T};

If !(Call _ARRAY_INITIALISED) Then
   {
   UKF_WMIKARRAY=[];
   };
does not work directly, since the function above returns 'scalar bool array string nothing 0xfcffffef' when the array is not initialised, which doesnt activate the 'if' clause. However, it does return 'true' when the array was init'd, and this means I could still use the general idea as a check. the new code (from the new versions) is as follows:

Code: [Select]
_checkVariable = {_bool = true; count _this >= 0; _bool};

if      (count _this == 3) then {
   _init = false;
   if ( FRG_Properties call _checkVariable ) then {
      _userPropertyArray = FRG_Properties;
      _init = true;
   };
   if (!_init) then {
      _userPropertyArray = [];   
      FRG_Properties = _userPropertyArray;
   };
} else {
   _init = false;
   if (count _this == 4) then {
      call format ["_userPropertyArray = %1", _this select 3];
      if ( _userPropertyArray call _checkVariable ) then {
         call format["_userPropertyArray = %1",(_this select 3)];
         _init = true;   
      };
      if (!_init) then {
         _userPropertyArray = [];
         call format["%1 = _userPropertyArray",(_this select 3)];
      };
   };
};

where _checkvariable returns either 'true' or scalar etc etc etc. Then the boolean '_init' is used to check whether the var was initialised (nb an else statement could not be used here. ) 'true' will activate the 'if', scalar etc will not, however if the 'if' is not activated then _init is left as false, telling the game to run the next 'if' statement after that.

UNN

  • Guest
Re:Properties for objects
« Reply #43 on: 18 Jul 2005, 09:24:38 »
Quote
does not work directly, since the function above returns 'scalar bool array string nothing 0xfcffffef' when the array is not initialised?

Are you sure you implemeted it correctly? You can run the following as a script from a trigger, and it will only execute the sidechat once. No matter how many times you keep calling it.

Code: [Select]
_ARRAY_INITIALISED={_T=True ; If (Count TESTARRAY>=0) Then {_T=False} ; !_T}

If !(Call _ARRAY_INITIALISED) Then {TESTARRAY=[] ; Player SideChat Format ["Run Once %1",TESTARRAY]}

_ARRAY_INITIALISED always returns false the first time you run it.

I wonder if somethings going wrong elsewhere, as the function you posted does not work when tried on it's own:

Code: [Select]
_checkVariable = {_bool = true; count TESTARRAY>= 0; _bool};

If (Call _checkVariable) Then {TESTARRAY=[] ; Player SideChat Format ["Run Once %1",TESTARRAY]};

The _CeckVariable function will always return true, even if TESTARRAY does not exist? I never got a single scalar error results as final output , from any of the functions?
« Last Edit: 18 Jul 2005, 09:29:50 by UNN »

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:Properties for objects
« Reply #44 on: 20 Jul 2005, 06:32:36 »
Apologies for my late reply, I was floored by a nasty bug within hours of posting last time, and I'm still recovering. :-\

I ran the script as you said, and the results were as you predicted.

I think the problem here is that i modified the inline function so that it reads:
_checkVariable = {_bool = true; count _this >= 0; _bool};
and takes an argument, instead of just checking a single array name such as 'TESTARRAY'. For some reason, this is when the scalar etc etc etc shows up.

 If you try this version, you will find you get the results i described:

[] call _checkVariable; result is 'true'

_array call _checkVariable; result is 'scalar bool array string nothing 0xfcffffef'

_array = [];
_array call _checkVariable; result is 'true'

The thing is, the user may specify their array to have any name they like, so it's easier to run a general check like this. The code from the new functions is also easy enough to follow, so nothing's been lost in that department.

Quote
I wonder if somethings going wrong elsewhere, as the function you posted does not work when tried on it's own:

I did a fresh test; created a new editor mission, d/l'ed the functions from the ed's depot, and did some basic tests. The functions worked fine. I've no idea what could be causing your problem