Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,388 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Dynamic Lights that turn on/off by distance #96051
10/26/06 00:54
10/26/06 00:54
Joined: Aug 2002
Posts: 572
Toronto
MadMark Offline OP
User
MadMark  Offline OP
User

Joined: Aug 2002
Posts: 572
Toronto
Greets,
I am (finally) a registered Extra version owner. I am creating my first level with A6, and am having a little problem with Dynamic Lights. All I want is to setup a simple on/off for lights in a corridor as the player approaches or leaves the light's range.

I guess the first question is does 6.40 Extra support dynamic lights?
Second, why would this not work?
Code:
  
<include My_Lights.wdl>;
...
entity* dynamiclight_1;

[in main]
Switch();

[in My_Lights.wdl]
function Switch
{
while(dynamiclight_1 == null){wait(1);} // wait until light exists!
while(1)
{
if(vec_dist (dynamiclight_1.x, Player.x) < 500) // check distance from the player
{
dynamiclight_1.light = on;
dynamiclight_1.lightrange = 500; // light on
wait(1);
}
}
}

action light_1 // attached to an invisible model
{
dynamiclight_1 = me;
my.light = off;
my.lightrange = 0;
my.red = 0;
my.green = 255;
my.blue = 255;
}




I've searched the entire forums for two days and can't figure this one out. I know there used to be a piece of code in here that does this, because I had it working in an old A5 script back in my "stumbling through demo version" days.

Anyone?

Mark


People who live in glass houses shouldn't vacuum naked.
Re: Dynamic Lights that turn on/off by distance [Re: MadMark] #96052
10/26/06 02:19
10/26/06 02:19
Joined: Jan 2003
Posts: 1,738
Nashua New Hampshire
anonymous_alcoho Offline
Senior Developer
anonymous_alcoho  Offline
Senior Developer

Joined: Jan 2003
Posts: 1,738
Nashua New Hampshire
The problem is that only one entity gets a pointer, even if there are multiple entities assigned the same action, so the way you have it set up should only work if there is one light.

There is only one player however. So you can set it up differently:

Code:
 
action dynLights //I like shorter names (:
{
while(!player) { wait(1); } //wait for player to exist
while(player)
{
my.light = (vec_dist(my.x,player.x) < 500); //turn on light if in range
my.lightrange = 500 * (vec_dist(my.x,player.x) < 500); //set lightrange if in range
wait(1);
}
}



Just be sure you have player = my at the top of your player code. Player is an engine defined pointer.

And what you have in the while are conditionals, its just a shorter way of doing an if-branch because conditionals always return 1 or 0. So if player is 600 away from the light my.light = 0;, therefore the light is off. my.lightrange = 500 * 0 = 0;, therefore there is no lightrange.

Dynamic lights are available in Extra. Colored are not.


"Oh no, it's true! I'm a love magnet!" Calvin from Calvin and Hobbes My name's Anonymous_Alcoholic.
Re: Dynamic Lights that turn on/off by distance [Re: anonymous_alcoho] #96053
10/26/06 17:53
10/26/06 17:53
Joined: Aug 2002
Posts: 572
Toronto
MadMark Offline OP
User
MadMark  Offline OP
User

Joined: Aug 2002
Posts: 572
Toronto
Thanks for the optimization tip, AA. I will definitely use it once I get to that stage. Makes total sense. I'll check "player=me" when I get home. I could have made an embarassing assumption.

There is only one light at this stage. I usually adopt the "Keep It Simple, Smart-a$$" methodology of code control when adding something new to my scripts. I try to isolate it as much as possible from my existing code, and only use 1 item at a time. Once I have that working, I look to increase the number if needed, and once that is working corectly, integrate it into my working code.

How do you long-timers manage your code changes?

Mark


People who live in glass houses shouldn't vacuum naked.
Re: Dynamic Lights that turn on/off by distance [Re: MadMark] #96054
10/26/06 19:17
10/26/06 19:17
Joined: Jan 2003
Posts: 1,738
Nashua New Hampshire
anonymous_alcoho Offline
Senior Developer
anonymous_alcoho  Offline
Senior Developer

Joined: Jan 2003
Posts: 1,738
Nashua New Hampshire
Start at the very basics and work up. Thats what I do.

For example, the tank in my RTS was built step by step.
First I made it so that I could selected it. Then I made it so I could selected multiple tanks. When that was done, I made it so I could move it. When that was done, I made it so I could move multiple tanks. Then I made it so it can attack enemies. . . and so on and so forth. Start at the bottom and work up.

You need to think: what does the object have to be able to do primarily before it can do anything else? and get that finished first.


"Oh no, it's true! I'm a love magnet!" Calvin from Calvin and Hobbes My name's Anonymous_Alcoholic.
Re: Dynamic Lights that turn on/off by distance [Re: anonymous_alcoho] #96055
10/27/06 01:00
10/27/06 01:00
Joined: Aug 2002
Posts: 572
Toronto
MadMark Offline OP
User
MadMark  Offline OP
User

Joined: Aug 2002
Posts: 572
Toronto
Cool. Thanks AA. I chased my tail through the new templates, and eventually found where the Player = Me; should be (plBiped01.wdl). Once I added that, and pasted your optimized code into my main wdl, worked like a charm. Moocho Graciass.

Works with multiple lights quite nicely. I aspire to write less spaghetti and more code.

We now return you to your regularly scheduled chaos and mayhem.
Mark


People who live in glass houses shouldn't vacuum naked.
Re: Dynamic Lights that turn on/off by distance [Re: MadMark] #96056
10/27/06 03:11
10/27/06 03:11
Joined: Jan 2003
Posts: 1,738
Nashua New Hampshire
anonymous_alcoho Offline
Senior Developer
anonymous_alcoho  Offline
Senior Developer

Joined: Jan 2003
Posts: 1,738
Nashua New Hampshire
Glad to see that one of my untested scripts worked on the first try

Your welcome


"Oh no, it's true! I'm a love magnet!" Calvin from Calvin and Hobbes My name's Anonymous_Alcoholic.

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1