Something random inside a scene?
Moderator: GZDoom Developers
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.
Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Something random inside a scene?
Is it possible to have something like "TNT1 A 0 A_StartSound("alert", CHAN_VOICE);" happen by random in a scene. I understand that I can just do a jump randomly to another scene, but that requires me to do another scene and jump back, if I keep doing that I end up with tons of small scenes everywhere.
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: Something random inside a scene?
Yes.
Code: Select all
TNT1 A 0
{
if (random() < 32)
{
A_StartSound("alert", CHAN_VOICE);
}
}
Re: Something random inside a scene?
Nice, is the number 32, 32 out of 255 here where 255 is 100%/1.0?
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: Something random inside a scene?
Yes. random(), without passing any args to it, returns a value that ranges from 0 to 255.
Re: Something random inside a scene?
Ok, I see.
I noted that this can't be "outside" a spritename (not sure what it's called really), but it has to be inside like in your example TNT1?
So this wont work, throws me an error:
TNT1 A 0 A_StartSound("alert", CHAN_VOICE); GUAA A 3 A_FaceTarget; { if (random() < 32) { GUAA F 4 Bright; } } GUAA B 3 ThrustThing(angle*256/360+192, 3, 0, 0); GUAA ABCD 4 A_Wander();
Because it assumes that the entire section there is suppose to be inside the a_facetarget sprite group?
I noted that this can't be "outside" a spritename (not sure what it's called really), but it has to be inside like in your example TNT1?
So this wont work, throws me an error:
TNT1 A 0 A_StartSound("alert", CHAN_VOICE); GUAA A 3 A_FaceTarget; { if (random() < 32) { GUAA F 4 Bright; } } GUAA B 3 ThrustThing(angle*256/360+192, 3, 0, 0); GUAA ABCD 4 A_Wander();
Because it assumes that the entire section there is suppose to be inside the a_facetarget sprite group?
-
- Posts: 5043
- Joined: Sun Nov 14, 2010 12:59 am
Re: Something random inside a scene?
No, it can't. The block of code in-between the curly braces (the outer ones, that is) is basically a function, and you can't have more than one function attached to a single state. So what you do is execute A_FaceTarget from within the anonymous function, like this:
Code: Select all
GUAA A 3
{
A_FaceTarget();
if (random() < 32)
{
// ...
}
}
Re: Something random inside a scene?
Ok, good to know. Had been even goodlier otherwise =)