ID:273987
 
mob/proc/OtherProc()
src.CalledProc("1")
//want to replace one using type???

mob/proc/CalledProc(r)
switch(r)
if("1")
for(var/obj/type1/O in src)
//SAME AS THE OTHER 2
if("2")
for(var/obj/type2/O in src)
//SAME AS THE OTHER 2
if("3")
for(var/obj/type3/O in src)
//SAME AS THE OTHER 2

Wondering how I can cut out the need for SWITCH() and jump straight into FOR()?
I'm guessing its either with type or text2path()? I tried the latter but didn't get it right :\
Look into the <code>text2path()</code> proc for dynamically setting a text string into a path, thus making what you want achievable.
mob/proc/CalledProc(r)
for(var/obj/Obj in src)
if( !istype(Obj, text2path("/obj/type[r]") ) )
continue
var/obj/type1/O = Obj // or type2 or type3 ?
// common code here


or, in a more decent way,

var/list/mytypes = list("1"=/obj/commontype/firsttype,"2"=/obj/commontype/secondtype,"3"=/obj/commontype/thirdtype)

mob/proc/CalledProc(r)
for(var/obj/commontype/O in src)
if( !istype(O,mytypes[r]) )
continue
// common code here


Where the commontype holds common vars and/or procs.
In response to Jemai1 (#2)
Is that really the only way I can do this?
I thought I knew how to do it but was just doing something slightly off... :(
In response to Saucepan Man (#3)
The latter is the most proper and simplest way of doing it.

Edit: If you hate associative lists, you can also do it this way
<dm>
mob/proc/CalledProc(r)
var/whattype
switch(r)
if("1")
whattype=/obj/commontype/blah
if("2")
whattype=/obj/commontype/blahblah
if("3")
whattype=/obj/commontype/blahblahblah
else
whattype=/obj/commontype/ // all
for(var/obj/commontype/O in src)
if( !istype(O,whattype) )
continue
// common code here
In response to Jemai1 (#2)
Just had a better look at your code snippet...
At first glance it looks like you've assumed i can only call it with "1" etc...
I'm able to type anything I like here - its totally flexible! :)
In response to El Wookie (#1)
I literally covered that in what I wrote... And explained that I musn't be using it right :\
I did re-check the ref. with no new clues uncovered...
/*
t could equal whatever i want it to
in this case:
*obj/objtype
*obj/objtype/subtype1
*obj/objtype/subtype2
*obj/objtype/subtype3
*/

RefreshJustuWindow(t)
for(var/obj/SkillCard/O) in usr
if(findtext(O,t)
//do stuff