Home   Help Search Login Register  

Author Topic: Searching for General barren  (Read 515 times)

0 Members and 1 Guest are viewing this topic.

RonMcAsskick

  • Guest
Searching for General barren
« on: 13 Oct 2004, 16:58:13 »
I'd love to buy you a pint man, that tip you gave me a while back about the use of conversion to create formatted script lines.  I experimented and i have got it going well, check some of the examples out below, so much faster and less loops!

from vietnam cti (MORE INFO : http://vietnamcti.freewebpage.org/)


; at top
   ?  (group player == westcommanderteam) : _resources = "westresources"
   ?  (group player == westalphateam)     : _resources = "westalpharesources"
   ?  (group player == westbravoteam)     : _resources = "westbravoresources"
   ?  (group player == westcharlieteam)   : _resources = "westcharlieresources"
   ?  (group player == westdeltateam)     : _resources = "westdeltaresources"
   ?  (group player == westechoteam)      : _resources = "westechoresources"
   ?  (group player == westfoxtrotteam)   : _resources = "westfoxtrotresources"
   ?  (group player == westgolfteam)      : _resources = "westgolfresources"
   ?  (group player == westhotelteam)     : _resources = "westhotelresources"

;on call
   _Conversion       = format["_needed = %1 - %2", _cost, _resources]
   _Conversion foreach [ 0 ]

   ?  (_Needed > 0)    : _Error = Format["Not enough resources! (Need $%1 more.)",_Needed] ; Hint _Error    ; goto "Update"
   _Conversion       = format["%2 = %2 - %1", _cost, _resources]
   _Conversion foreach [ 0 ]
   _Conversion       = format["PublicVariable ""%1""", _resources]
   _Conversion foreach [ 0 ]


My personal fave

   _Closest       = ObjNull
   _ClosestDistance    = 9999
   _Conversion    = format["""_distance = _unit distance _x ; if (_distance < _ClosestDistance) then {_ClosestDistance = _Distance ; _Closest = _x}"" foreach West%1Factory", _SelectedObjectType]
   _Conversion foreach [ 0 ]

as a note if you use a local variable (ie one beginning with _) then it has to be declared outside the _conversion bit, otherwise it just doesnt work, weird huh?

cheers again man

if anyone would like help using this method i'd be happy to explain, just msn me at feliix1956@hotmail.com

ron
« Last Edit: 13 Oct 2004, 19:35:01 by RonMcAsskick »

Offline General Barron

  • Former Staff
  • ****
  • Semper Fi!
Re:Searching for General Barron
« Reply #1 on: 15 Oct 2004, 17:44:47 »
Lol... you know you could have used a PM  ::). That's okay though, because it's Barron, not Barren, so it wouldn't have gone thru anyway :).

Anyway, glad to see you're getting some good use out of that handy little trick. It definately opens up a ton of doors in terms of scripting, as you can see. However, I will take absolutely no credit for the idea, because I actually learned it from the brilliant guys at the Chain of Command (namely Dinger). I've found a lot of uses for the format command myself, aside from the way the CoC uses it. They use it a little differently though, and they actually create variables dynamically (in UA) by also using the "call" command. For example:

call format["%1 = 1000", name player]

So if the name of the player was "Bob", then the above would create a global variable called Bob that would have the value 1000. To retrieve this variable, you would use:

call format["_value = %1", name player]

Which would then put that 1000 in the local variable _value (which has to be declared already, as you know).

Quote
as a note if you use a local variable (ie one beginning with _) then it has to be declared outside the _conversion bit, otherwise it just doesnt work, weird huh?
Yeah, I've found that out the hard way more than once  ;) ("What the heck is going on with this ($@*%#$ script?!?!?!?"). It actually has to do with locality of variables, and you'll see how it makes sense if you ever try defining a function inside of a script ( _myfunction = {blah blah blah...} ).

Quote
if anyone would like help using this method i'd be happy to explain, just msn me at feliix1956@hotmail.com
Perhaps you (or we) should write a tutorial, so nobody has to repeat themselves?

Btw.... I don't even remember when/how I explained this to you (though I have a guess). Could you point out the thread perhaps?
« Last Edit: 15 Oct 2004, 17:45:51 by General Barron »
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!

Offline XCess

  • Former Staff
  • ****
Re:Searching for General barren
« Reply #2 on: 16 Oct 2004, 06:34:50 »
tutorial sounds very god to me. Also like the sound of opening doors in scripting (it would be so much easier to call it .sqs dont u think?)

RonMcAsskick

  • Guest
Re:Searching for General barren
« Reply #3 on: 17 Oct 2004, 06:08:17 »
sorry about the mispelling

I'd be up for writing a tutorial, never done it before though.

I'll put something together and get in touch for your two pennies worth as well.

Thanks again, Vietnam CTI wouldnt be so completed without you

Ron