Home   Help Search Login Register  

Author Topic: String manipulation  (Read 810 times)

0 Members and 1 Guest are viewing this topic.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
String manipulation
« on: 29 Oct 2004, 15:20:52 »
It was a great dissapointment to find that I cannot use >, >= etc when comparing strings.  I therefore need to be able to access individual characters in a string - or at the very least I need to be able to truncate a string to a specific number of characters.

I have looked in Comref and in the functions in the Editor's dept.  Can anyone help?


Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:String manipulation
« Reply #1 on: 29 Oct 2004, 15:41:05 »
How does the string look like?

:beat: *Gets Shot* :beat:

Offline KTottE

  • Former Staff
  • ****
Re:String manipulation
« Reply #2 on: 29 Oct 2004, 15:59:09 »
Here's one of the areas when OFP Script fails.

What are you trying to do anyway?
"Life is not a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside, thoroughly used up, totally worn out, and loudly proclaiming 'WOW What a Ride!'"

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:String manipulation
« Reply #3 on: 29 Oct 2004, 18:42:06 »
I want to find all the objects of a particular type on the map.  I have written a script that  gets the typeOf for each object in turn (It is a script to help with making a mission not to be run during a mission - it takes ages) and checks the result against a string to see if there is a match.  I want to be able to check only part of the string.  Currently I check each of:
"StreetLampPanel"
"StreetLampMetal"
"StreetLampWood"
"StreetLampPanelAmpl"
"StreetLampYellow"
"StreetLampCut"

and I may not have all the streetlamps there.

What I want to do is to take only the first few characters of the result from the typeOf and then match that against a string.  For example I could match the first 6 characters from typeOf against the string "Street".  That way I would get all the streelamps I know about and all the ones I don't as well - all with one check.

Similarly I could run the script matching the first 4 characters of the typeOf result agains "Fuel" to get all the fuel stations of any type.

When it find a match the script displays the object number.

Armsty:  I hope the above also answers your question.

Offline Sui

  • Former Staff
  • ****
    • OFPEC
Re:String manipulation
« Reply #4 on: 30 Oct 2004, 01:59:51 »
As far as I know, BIS didn't include the possiblity of phrasing strings in OFP :(

If it's possible I'd love to know how... :)

Offline Blanco

  • Former Staff
  • ****
Re:String manipulation
« Reply #5 on: 30 Oct 2004, 03:40:35 »
Just asking to be sure I understand you right...

Do you have to know the object id for every streetlamp in general or for every single streetlamptype? (in an array maybe)
)
Now I hope you understand me  :-\

 :)

 Anyway, I was thinking, why not workingh in the other way?
Object id's are numbers and numers can be updated so...

I tried something on Malden, I could return the id's from one type of streetlamp, but it takes some time (more than a minute to check 50000 objects)...


Code: [Select]

; you have to know how many object there are on the island, so took 50000 just to test, there are much more on island offcourse
_maxid = 50000

_ids = []

_i = 0
#loop
if (typeof object _i == "StreetLampMetal") then {_ids = _ids + [_i] } else {goto "checknext"}

#checknext
?_i > _maxid : hint format ["%1",_ids];exit
_i = _i + 1
goto "loop"
 

Run it with
[] exec "whatever.sqs"

and wait a minute...

Return was [1251,2003,28419,28420,32938,37326,28424,28664]

Al these objects id's are  "StreetLampMetal" lamps stored in the _ids array.

Offcourse I only check one object here and I'm 50000 of them, but I think you got the point.
The delay in the loop is nada, so it will take a loooong time when you check every object on the island

Hope it helps m8!


« Last Edit: 30 Oct 2004, 04:49:32 by Blanco »
Search or search or search before you ask.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:String manipulation
« Reply #6 on: 30 Oct 2004, 04:07:26 »
He was trying for every streetlamp type.

But I think he hopes to be able to apply the script for any object at all that is embedded in a wrp file.

In fact I do believe there is only one streetlamp type on Malden anyway.

Planck
« Last Edit: 30 Oct 2004, 04:08:49 by Planck »
I know a little about a lot, and a lot about a little.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:String manipulation
« Reply #7 on: 30 Oct 2004, 07:49:43 »
Blanco:

Thanks, you have just shown me a script to do exactly what my script does - except yours does it in a much better way than mine ::)

This started when I wanted to find all the streetlamps in Malden so I could set them to OFF.  Then I thought, well I want to make sure most of the fuel stations are dead as well.  So then I wrote a script to find all the object numbers of a given type.  The problem is - the script needs to be told the exact object name.  This has two problems: 1. I don't know them all; and 2. it will not find generic types of objects.

For example:  I wanted to search for all objects where "Fuel" are the first 4 characters; or where "Church" are the first 6 characters etc. etc.  That way I would find all objects of a given type even without knowing the full names for them.

It seems this is not possible - or if it is then the method is not known.

Planck:  Yes you are right.  Anyway having seen Blanco's solution I will use that in future, not the one I wrote.
« Last Edit: 30 Oct 2004, 07:53:49 by THobson »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:String manipulation
« Reply #8 on: 30 Oct 2004, 13:08:30 »
Quote
Return was [1251,2003,28419,28420,32938,37326,28424,28664]

Hey Blanco, you nearly got them all.
You would have needed to go to almost 100,000 to get the last 4 though.

Numbers were:

66997
66998
67026
90863


Planck
I know a little about a lot, and a lot about a little.