Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Defining a random x
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#1
Defining a random x

I want to set a random variable from 1 to 4 that will determine which entity out of 4 is activated, but I'm not sure how to connect the two things. But, I don't know how to call x when I am setting the script.

I know to set the random variable, I want to do:

SetLocalVarInt("OrbPiece", RandInt(1,4));

And to activate the orb when you enter the corresponding orb piece, doing something like this:

SetEntityActive("orbpiece_emerald_"+x, true);

Where x is set equal to the integer generated by the first script. So how do I set them equal to each other?

(This post was last modified: 04-23-2012, 10:54 PM by Damascus.)
04-23-2012, 06:07 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#2
RE: Defining a random x

Have you forgotten about GetLocalVarInt?

Tutorials: From Noob to Pro
04-23-2012, 07:08 AM
Website Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#3
RE: Defining a random x

Right, I know that, but I haven't found any guides for setting x equal to something. Do I literally just:

SetEntityActive("orbpiece_emerald_"+GetLocalVarInt("OrbPiece");, true);

or

for x = GetLocalVarInt("OrbPiece");
SetEntityActive("orbpiece_emerald_"+x, true);

Sorry, I'm sure this is very obvious to you, but I haven't done a lot of work with using i or x outside of "for" loops, and I'm fairly sure that doesn't apply in this situation. I'm totally in the dark for how to define "x" as a local variable.

Or now that I think on it some more, it might just be easier to bypass the whole local variable nonsense and do this:

SetEntityActive("orbpiece_emerald_"+RandInt(1,4), true);

(This post was last modified: 04-23-2012, 07:26 AM by Damascus.)
04-23-2012, 07:23 AM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#4
RE: Defining a random x

(04-23-2012, 07:23 AM)Damascus Wrote: SetEntityActive("orbpiece_emerald_"+RandInt(1,4), true);

That would work, but if the only time you've ever declared a variable has been inside for loops, then that sounds like you've taken the copy-and-paste approach to things and the kind of research you need to do concerning variables is learning how to declare and initialize variables.

Tutorials: From Noob to Pro
04-23-2012, 08:03 AM
Website Find
Knittel Offline
Junior Member

Posts: 8
Threads: 1
Joined: Apr 2012
Reputation: 0
#5
RE: Defining a random x

But pay attention. If you want activate more than 1 of those objects by that, it may be that you activate the same object multiple times. I don't how exactly you want to use that code, but this would be the same problem, when making a program generating 6 diffrent numbers between 1 and 10. You need to pay attention that there isn't a number chosen, which was already used.

So a solution should look something like:

NotFoundANewOne = true;

while (NotFoundANewOne) do

{

x = random(1,4);

if ("Object" + x) is already active then

NotFoundANewOne = false;

}

Set ("Object" + x) = Active

(This is NOT code for the Amnesia script, but it shows the principle of what is to be done.


[Image: 2ZwH0ZGD0AwL2.png]
[TRACKMANIA]


(This post was last modified: 04-23-2012, 01:21 PM by Knittel.)
04-23-2012, 01:19 PM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#6
RE: Defining a random x

No, I'm just going to be activating a random one out of four. It's a critical item you have to find, but I'm basically randomizing its location when you enter the level. I did some research, but I think this is basically what I'm going to have to do:

void OnStart()
{
AddEntityCollideCallback("Player", "ActivateRemnant", "ActivateRemnant", true, 1);
}

void ActivateRemnant(string &in asParent, string &in asChild, int alState)
{
int x = RandInt(1,4);
SetEntityActive("orbpiece_emerald_"+x, true);
FadeLightTo("OrbLight_"+x, 0.3f, 0.6f, 0.5f, 1, 0.5f, 1);
}

04-23-2012, 08:01 PM
Find
Cranky Old Man Offline
Posting Freak

Posts: 986
Threads: 20
Joined: Apr 2012
Reputation: 38
#7
RE: Defining a random x

I have no idea what you mean, BUT:
I saw some odd looking entity location randomization code for stones in the beginning of the .hps for the Archives map.
You might want to check that out.


Noob scripting tutorial: From Noob to Pro

(This post was last modified: 04-23-2012, 08:08 PM by Cranky Old Man.)
04-23-2012, 08:07 PM
Find
overscore Offline
Junior Member

Posts: 10
Threads: 1
Joined: Apr 2012
Reputation: 1
#8
RE: Defining a random x

Writing x = y will make whatever x is, equal to y.

Ex. x = 5
x = y
y = 5


if you write x == y like an if statement. Basically its asking if x is the same as y.

if(x == y)    
{       //then do this    
}


Is that what you mean?

(This post was last modified: 04-23-2012, 08:11 PM by overscore.)
04-23-2012, 08:10 PM
Find
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#9
RE: Defining a random x

There's no need for any proxy variables or handles or anything like that. Simply do the SetEntityActive("object_"+GetLocalVarInt("variable"), true);

Semi-colons end statements, they aren't used after all functions. It is just happenstance that the majority of statements in Amnesia scripting are functions. Think of it as a period. You don't speak. Like this. You speak like this. Smile

I'd also suggest making use of the variable anyways, instead of hard-coding the random integer generation into the script. That allows you to use debug messages with the variable and do plenty of other scripting goodness that might involve that variable (in this case, the index of the object, or orb piece).

04-23-2012, 08:40 PM
Find
Damascus Offline
Senior Member

Posts: 646
Threads: 118
Joined: Mar 2012
Reputation: 29
#10
RE: Defining a random x

To clear things up, here's what I'm trying to do: You enter a map looking for a crucial item. I've set up five possible locations where it could be. When you hit a script area entering the level, it activates the orb in one of those areas at random. That way you never know where it will be.

I used the script in my latest post and it is working like a charm. I did want to define a variable cause I'm lighting up the corresponding PointLight that's going to be surrounding it.

04-23-2012, 10:53 PM
Find




Users browsing this thread: 2 Guest(s)