Please or Register to create posts and topics.

Need Help With Scripting

PreviousPage 2 of 5Next

I got the following to work:

Code: Select all
didSetCubes <- false;
DBG <- 1 //set to 0 once finished debugging

//Change all the models of the cubes to custom ones
function setCubes() {     
   local baboo = null

   //retrieve all cubes with the name Test_Cube and set their model to metal_boy
   while((baboo = Entities.FindByName(baboo,"Test_Cube")) != null){
      if(DBG)printl("found cube!")
      if ( baboo.IsValid() ) baboo.SetModel("models/props/metal_boy.mdl")}
   }
   didSetCubes = true;
}

setCubes() //Set all cubes models on level start
if(DBG)printl("setted the cubes! " + UniqueString())

I will add IsValid to the list of Portal 2 functions on the wiki.

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

Ill check if this setup works for me. Thanks for the help, I really appreciate it.

This Signature is Beyond Your Range of Seeing.

Image

Hey,

I copy and pasted exactly what you put in the code, and ran the map with it, and I got the same exact error. I put this in:

didSetCubes <- false;
DBG <- 1 //set to 0 once finished debugging

function setCubes() {
local baboo = null

while((baboo = Entities.FindByName(baboo,"Test_Cube")) != null){
if(DBG)printl("found cube!")
if ( baboo.IsValid() ) baboo.SetModel("models/props/metal_boy.mdl")}
}
didSetCubes = true;
}

setCubes()
if(DBG)printl("setted the cubes! " + UniqueString())

How did you actually implement yours in your test map? I'm just using a logic_script with the entityscripts property this code, and having the logic_script RunScriptCode .1 seconds after an env_entity_maker spawns an entity. Is there something wrong in doing this?

This Signature is Beyond Your Range of Seeing.

Image

You do not even need to RunScriptCode as it will auto run because of setCubes() at the end of the code. To test out whether a script is working manually is to type in the console: ent_fire bignet runscriptfile o. It will tell you if there is any errors and where in the code or if the script you are referencing actually doesn't exist.

I assume your script is scripts/vscripts/o.nut

Notes on code:

Spoiler
I didn't understand what the IsValid() function check was for but I understand now. It is just a backup to check if the entity found with the name is actually a valid entity (or one that exists).
I believe if you delete the if ( baboo.IsValid() ) it will still work fine. Though I would keep it in anyway.

There is no point in creating the didSetCubes global variable if you are not going to reference it later. Because the function setCubes() is executed on startup, I don't see why you need this at all.

Lastly, try to keep variable names descriptive. I'm not sure if baboo means anything in another language but I would have called it currentCube or foundCube. Remember you can add comments to your code for someone else to better understand by two slashes //

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

No it's not, that's what I can't figure out. It is scripts/vscripts/cubeswitch.nut

I don't know where it is getting that o.nut from. Any idea?

One thing that might be helpful, I'm saving it as a .nut file, and the file type shows it as a .nut, but when I save it, I save it as a .txt file using Notepad++

This Signature is Beyond Your Range of Seeing.

Image

.nut files are just pure code, it shouldn't matter what sort of encoding it is saved with.

Double check that your logic_script is actually pointing towards your script file.

script2.jpg

Click the Manage button and highlight your script in the menu and click open source. If it doesn't open any file or the wrong one, then change it to suit. If there are multiple files in the dialog, then delete (-) the wrong one and add (+) the right one in.

script-2.jpg

Lastly: when you spawn the cube and change the cube model, it would be more efficient to change the model of the cube that you have just spawned.
This could probably be done by creating a trigger which the cube passes through when spawned.

OnStartTouch > !activator > RunScriptCode > setCubeModel(self)

And in your script file:

Code: Select all
function setCubeModel(cube){
   cube.SetModel("models/props/metal_boy.mdl")
}

So the final code would look something like this:

Code: Select all
function setCubeModel(cube){
   cube.SetModel("models/props/metal_boy.mdl")
}

function setCubes() {     
   local baboo = null

   while((baboo = Entities.FindByName(baboo,"Test_Cube")) != null){
      if ( baboo.IsValid() ) setCubeModel(baboo)
   }
}

setCubes()
printl("setcubes " + UniqueString());

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

Hey, here is everything on the comp, I can't get this thing working, maybe looking at it will help you see what is wrong.

This Signature is Beyond Your Range of Seeing.

Image

Oh, also there is only one file, and when I hit open source, it does not open it. How do I change it to suit? Under the manage list it is currently under scripts/vscripts/cubeswitch.nut

This Signature is Beyond Your Range of Seeing.

Image

I have a feeling that your windows is being decieving and saving the file as cubeswitch.nut.txt. Enable file extensions on windows and remove the .txt from the end of your file.

Also why is your steamapps folder on your desktop? I doubt that would even work.

EDIT: I see your problem. Remove the scripts/vscripts in the path and it will work. It looks for scripts relative to that path.
e.g. chicken_scripts/o.nut NOT scripts/vscripts/chicken_scripts/o.nut

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

@Tmast98: when you are going to save the file in Notepad++ just select "All Types(*.*)":

Image

ImageImageImageImageImageuseful tools and stuff here on TWP :thumbup:
[spoiler]ImageImageImageImageImage[/spoiler]
PreviousPage 2 of 5Next