ID:158355
 
Hey. So, this is the findtext() proc:

findtext(Haystack,Needle,Start=1,End=0)

Well, I have an instance where I want to check for multiple "needles" at once but in the same haystack. Here is what I currently have:

mob/proc/Play_File(file/S)
if(findtext("[S]",".bmp")||findtext("[S]",".png")||findtext("[S]",".jpg")||findtext("[S]",".gif"))
world<<browse(S)


I have to repeat findtext() a lot. Is there any other way of doing this that is better/shorter?

Thanks.

And if this is not possible, is it something I should put in the suggestions forum? Or not?

It would be nice if I could do something like this:

mob/proc/Play_File(file/S)
if(findtext("[S]",list(".bmp",".png",".jpg",".gif")))
world<<browse(S)


But I think that would search for the actual entire list in a text string, so it wouldn't find anything. But I really do not know.
You're just going about it the wrong way. If you need to compare it to a lot of values, first isolate the file's extension, then... compare it. To do so you of course need to find the position of the last dot in the filename, then copytext everything that's after it.
You can always use a proc.
proc/fndtext(var/Hay,var/list/Needle,var/Start,var/End)
if(!Hay||!Needle) return 0
if(!Start) Start=1
if(!End) End=0
var/Out=0
for(var/n in 1 to Needle.len)
var/Tmp=findtext(Hay,Needle[N],Start,End)
if(Tmp&&((Tmp<Out)||(Out==0)))
Out=Tmp
return Out
mob/verb/Test(var/Text as text)
var/B=fndtext(Text,list("0","1","2","3","4","5","6","7","8","9"))
if(B)
world<<"The first number appears at position [B]"
else
world<<"No numbers to be found 3:"

Edit:Updated
In response to Chowder
Chowder wrote:
You can always use a proc.
>   for(var/N=Needle.len,N>0,N--)
>

You're searching through the list backwards. Would make more sense to go from beginning to end.
for(var/n in 1 to Needle.len)
In response to Kaiochao
Hm, is there a difference with the latter snippet and this?
for(var/n=1 to Needle.len)
In response to GhostAnime
Not really, "in" and "=" are similar in a couple things.
In response to Chowder
Yea that would work great. Thanks for the examples.
In response to Dragonn
!!
My suggestion was completely ignored! I am officially awestruck.