Notifications
Clear all

[Closed] Testing against an objects name

Hi again,

 Sorry for posting agian, but I am so close, I just can't stop!! 
 
 I am trying to make a script that quickly assigns wall pieces to a set of splines, but I only want 1 door for every run of the script. I am getting stuck trying to do an if test against the object, so anything starting with D*, I'd like it to go through the test.
 
 I've searched and found heaps of posts regarding the .name, but I haven't been able to find any posts talking about conditional tests against a name.
 
 Any help appreciated, or even a kick in the right directon! What am I missing here

  
  WallTypes = $W* as array
  GuideMap = $Line* as array
  DoorTest = 0
  x = "Success"
  y = "Fail Success"
  
  
  for i = 1 to GuideMap.count do
  	(
  		
  		r = random 1 WallTypes.count
  		
  		if WallTypes[r].name == "Door*" Then 	
  			
  			Print x
  			
  		Else
  		
  -- 		NewWall = instance WallTypes[r]
  -- 		NewWall.transform = GuideMap[i].transform
  
  			Print y
  				
  	)
  
  
    
4 Replies

if matchpattern WallTypes[r].name pattern:“Door*” Then

Create the door first, exclude that part and iterate only over the rest of the collection. Basically:

WallTypes = $W* as array
GuideMap = $Line* as array

r = random 1 GuideMap.count
-- make door here
deleteItem GuideMap r

for guide in GuideMap do
(
	instance WallTypes[random 1 WallTypes.count] transform:guide.transform			
)

Thanks guys,

Miauu (are you the scriptpack guy) thats handy to know, I didn’t know about that pattern, much appreciated!

Swordslayer, wow thanks, that is a much cleaner logic, however I have some werid results at the moment and a few things I don’t understand.

  1. The deleteitem, actually deletes the mesh from the WallType array? I don’t get how that happens I assumed that it would delete the line from the GuidMap array??

  2. I just wanted to understand how you made the WallTypes align up without referencing the GuidMap array when you did

instance WallType[random 1 WallType.count] transform:guide.transform		

I can’t see how its working, but it is??

Thanks!

  1. it deletes the item (reference to a node) from the GuidMap array, which means that when you iterate over the GuidMap array in the next step, the part where the door were create won’t be used again

  2. have a look at For Loop By Index Vs. For Loop Through Collection

The weird result might be caused by transforms of walls and guides not aligning properly or a myriad of other factors, hard to guess without knowing what makes them weird to you in the first place. All in all, read the help file and read it thoroughly, it pays off.