Please or Register to create posts and topics.

Need Help With Scripting

Page 1 of 5Next

Hi,

I'm trying to replace certain prop_weighted_cube entities using scripts, but for some reason it isn't working. Here is a copy of the script I created.

Code: Select all
function setCubes(){      
      baboo <- null;
      while((baboo = Entities.FindByName(baboo,"Test_Cube")) != null){
            
            if ( baboo.IsValid() ){
               baboo.SetModel("models/props/metal_boy.mdl");
            }
                  
      }
      didSetCubes <- true;
}

setCubes();
printl("If you're seeing this, the <Holiday Name Here> script loaded without a hitch. Yay" + UniqueString() );

I have this set to runscriptcode and to runscriptfile by a logic auto when the map spawns, and have the env_entity maker which makes the Test_Cube runscriptcode and runscriptfile after .1 seconds of spawning an entity.

When the logic_script is triggered I get the following error.

"script not found (script/vscript/o.nut)"

I have saved the .nut file into the vscripts folder under portal2 though, any ideas on how to get this to work?

Thanks in advance

This Signature is Beyond Your Range of Seeing.

Image

You've mistyped the path to the script, it should be scripts/vscripts/whatever.nut.

Falsi sumus crusto!

Okay, I fixed that, but I am getting this as well now

"Entity CubeSwitch found error in RunScript0"

CubeSwitch is the name of the logic_script using the code above. Do you know why this would happen?

This Signature is Beyond Your Range of Seeing.

Image

What is metal_boy?

baboo.SetModel("models/props/metal_boy.mdl");

That may be a problem if it isn't a custom prop.

?????????????????????????????TWP Releases | My Workshop
ChickenMobile wrote:
What is metal_boy?

baboo.SetModel("models/props/metal_boy.mdl");

That may be a problem if it isn't a custom prop.

metal_boy is the name of the new model to replace the cube. It is a custom model.

This Signature is Beyond Your Range of Seeing.

Image

Oh, did you check your model in the model viewer?

Yeah, the model is there and fully works. It works on it's own as a prop_physics, but I need the cube to respawn using droppers, and prop_physics don't have dissolve inputs, nor does manually just putting it in work, so the best way I figured would just script the cubes to reskin themselves.

This Signature is Beyond Your Range of Seeing.

Image

Is IsValid() even a Portal 2 function? If you're trying to check if baboo is set to your cube you should compare it to null

EDIT: also if you are only using names inside a function you should declare it as variable and not a global variable.
e.g. baboo <- null to local baboo = null

?????????????????????????????TWP Releases | My Workshop

Yeah its valid, its a Portal 2 function. I'm new to scripting so the rest of that just went over my head. I think I am wanting baboo to be set to the cube? So how do I compare it to null?

Sorry for not understanding that fully :/.

This Signature is Beyond Your Range of Seeing.

Image

Oh I think I get it, since Test_Cube is not a global entity, but a name of a specific entity, I have to declare this differently? Now how do I go about doing this?

I changed the code to this and still got same error

function setCubes(){
var baboo <- null;
while((baboo = Entities.FindByName(baboo,"Test_Cube")) != null){

if ( baboo.IsValid() ){
baboo.SetModel("models/props/metal_boy.mdl");
}

}
didSetCubes <- true;
}

setCubes();
printl("If you're seeing this, the valentine script loaded without a hitch. Yay" + UniqueString() );

This Signature is Beyond Your Range of Seeing.

Image
Page 1 of 5Next