Please or Register to create posts and topics.

Question about variables, values, and scripting.

Page 1 of 2Next

This is my first attempt at scripting for a portal 2 map, so I may be missing something obvious. In the class info for an entity, I want to make a value a variable. Once I've got that, my hope is to be able to change this value dynamically in the chamber. I've written a couple simple scripts to create the global variable and set it to whatever I want when the script is called with an appropriate argument. I tried just typing in the variable name in the box, that doesn't work. I also tried opening up the .vmf in notepad++ and deleting the quotes around the value, but it added them back automatically. My only experience with scripting with squirrel so far is a tutorial I found on gamebanana.

My script that I'm testing the concept with is this:
function onebyone(target) {
target1x1 = target;
}
And the other is this(triggered from a logic auto):
target1x1 <- target;

Does anyone know why this isn't working, and what I need to know to get it working? There may be a way to do this without scripting, but I want to use this to learn.

I can't really tell what you're trying to do. What is "target"? You haven't assigned a value to it, and it isn't a built-in variable.

Falsi sumus crusto!

The one in the first script is a local variable assigned as an argument. The one in the second script is a place holder. I was just trying to declare the global variable there. I'm not completely sure how that is done, but I've experimented by giving it a few different types of values.(Like "Track_1x1" both with and without the quotes(track_1x1 is the name of the entity I'm trying to switch the value to.)) For that second script, target is just a placeholder.

I still don't quite understand what the problem you're having is. But you can't pass strings to functions directly from the map in Portal 2, because the quote marks around the argument confuse Hammer. That might be the issue.

Falsi sumus crusto!

ok, I'm not sure what format it needs to be entered in. I wasn't putting in a string in the argument. I tested by taking out the argument making the function set the variable to to what I want in the format of a string. If I'm not explaining it right, this is what It looks like now:
function onebyone() {
target1x1 = "Track_1x2";
}

And the other one that I added to declare the variable as a global variable is this:
target1x1 <- "Track_1x1";

It still isn't working. When I test it in the map, I get this error:
AN ERROR HAS OCCURED [the index 'target1x1' does not exist]

I believe my main problem is that what I'm trying to use as a variable is not acting as a variable, but instead the specific target itself. Not in my code, but in hammer. Specifically, I am trying to be able to dynamically change the "next stop target" of a path_track by putting a variable in the place of the value. I'm not sure if it's possible, but if it is, I'm convinced that I'm not doing it right.

If you want to do that use AddOutput, or even just alternate paths. Don't bother setting up a script.

Variables have three types of scope: local, entity-global, and map-global (I'm sure there are better terms for this, but I don't know them).

Local (goes out of scope when its block ends):

Code: Select all
local x=20;

Entity-global (available for all functions in an entity's script):

Code: Select all
x <- 20;

Map-global (available for everything in your map):

Code: Select all
::x <- 20;

I'm guessing your two functions are executed on different entities.

Falsi sumus crusto!

ok, Thanks for your help. I've been hoping for something easy I could work with to give me a start into scripting.(I really want to sometime soon), but I'm guessing this is not the time to do that. I'll try just using addoutput then.

If you want an easy (but interesting) scripting problem, try implementing a simple minigame in VScript. Perhaps a cellular automaton with cube buttons for input and output?

To make it even more interesting, only use three entities in your VMF: a player start, a script, and a logic_auto. ;)

Falsi sumus crusto!

Thanks, I'll look into that.

It sounds really hard, but it's a lot easier than it looks. I suggested it because it would be nearly impossible in Hammer alone.

Falsi sumus crusto!
Page 1 of 2Next