Need Help With Scripting
Quote from Tmast98 on July 8, 2013, 7:01 pmHi,
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
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
Quote from FelixGriffin on July 8, 2013, 10:52 pmYou've mistyped the path to the script, it should be scripts/vscripts/whatever.nut.
You've mistyped the path to the script, it should be scripts/vscripts/whatever.nut.
Quote from Tmast98 on July 8, 2013, 11:07 pmOkay, 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?
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?

Quote from ChickenMobile on July 9, 2013, 1:00 amWhat is metal_boy?
baboo.SetModel("models/props/metal_boy.mdl");
That may be a problem if it isn't a custom prop.
What is metal_boy?
baboo.SetModel("models/props/metal_boy.mdl");
That may be a problem if it isn't a custom prop.
Quote from Tmast98 on July 9, 2013, 1:14 amChickenMobile 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.
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.

Quote from Tmast98 on July 9, 2013, 1:22 amYeah, 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.
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.

Quote from ChickenMobile on July 9, 2013, 1:33 amIs 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
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
Quote from Tmast98 on July 9, 2013, 1:41 amYeah 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 :/.
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 :/.
Quote from Tmast98 on July 9, 2013, 1:48 amOh 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() );
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() );