Please or Register to create posts and topics.

Scripting Questions, FindByClassnameNearest()

Hey guys, I'm trying to write a script that can be run in multiple places in the same map, each time from within it's own instance. There are 2 entities in the instance that I want saved as variables. When I set the instance to not prefex or suffex the name, then I can easily store the entities to the name with FindByName(). This was great for testing, but to make this instance an easy plug-and-play instance, I cannot use this method. So what I tried next was:

Code: Select all
laser_emitter <- Entities.FindByNameNearest("*Rev_Red_Laser",self.GetOrigin(), 32)
target_ent <- Entities.FindByNameNearest("*Rev_Red_Laser_end",self.GetOrigin(),32)

I did this after setting the instance to set a prefix to the name again. When things weren't working as I expected, and I tested with printl(target_ent.GetName()), it gave me the name of the object running the script: "(prefix)-Rev_Red_Laser_start". Does a '*' at the beginning effect the entire string? I would think it would be for just the beginning. I next tried this:

Code: Select all
laser_emitter <- FindByClassnameNearest("prop_dynamic", self.GetOrigin(), 32);
target_ent <- FindByClassnameNearest("info_target", self.GetOrigin(), 32);

It however seems like portal doesn't recognize the FindByClassnameNearest() function because after I entered this, it started saying that main() does not exist. (main() is the first function called.) I don't understand why this is giving me so much trouble. Are these functions known to have issues? Is there anything I'm doing that would make these functions not work?

I don't know. The only thing I know is that you can just use multiple names and scripts.

I just reminded one script I recently read which opens nearby (to the player) linked_doors. The function used is "FindByClassnameWithin()" though, but it might help you out to get your goal anyways:

open_nearby_portal_linked_doors.nut

Spoiler
Sorry, only logged-in users can see spoilers.

The usage of that function makes me think the rest ones are also actually functional....

ImageImageImageImageImageuseful tools and stuff here on TWP :thumbup:
[spoiler]ImageImageImageImageImage[/spoiler]

Forgot the "Entities." I got it working now. Don't worry about the findbyclassnamenearest questions, but the glitch with the '*' still confuses me, so if you understand what was happening there, some clearification would still be nice.

AFAIK wildcard matching in Source is fairly weak: a star literally means something like "if it matches up to this point, say it was a valid match". So you can only use it meaningfully at the end of the name.

If you are having fixup difficulties, you can put the instance inside another instance, and set the inner func_instance's fixup mode to "none".

Falsi sumus crusto!

I also reminded that HMW wrote a script using the FindByClassnameNearest() function (I knew I had already seen it before :p):

sticky_panels.nut

Spoiler
Sorry, only logged-in users can see spoilers.

Maybe that one could help you out a bit more.

I used the asterisk as wildcard for some I/O in Hammer in the past succesfully... however, you might be having an issue with "finding the nearest" while saying "all entities starting by Rev_Red_Laser_end" (which could be not meaning any), could that be?

ImageImageImageImageImageuseful tools and stuff here on TWP :thumbup:
[spoiler]ImageImageImageImageImage[/spoiler]

Thanks for the help guys.

One thing you could do instead is just self.GetName(), then do some string editing to find out what the user named your instance and then get a handle to the other entities.

My stuff:
[spoiler]- BEE2 Addons | (BEE2)
- Hammer Addons
Maps:
- Crushed Gel
- Gel is Not Always Helpful[/spoiler]

EDIT.

greykarel wrote:
blah-blah-blah about some problem with a script

I don't now whay was wrong before but today it works fine.

God bless the quick save's inventor...(Portal: Prelude)