Question about scheduling rain
by dragonlady · in Technical Issues · 12/08/2007 (6:35 pm) · 7 replies
Good evening everyone :)
This is my first time post. Pleased to meet you all :) I'm new to Torque programming, so I'm probably making an obvious mistake here and not realizing it. Here's what I'm trying to accomplish: upon loading my mission, I want an object that schedules rain to start and stop at random times. What I originally wanted was for the object to be created and initialized from the start without any user input, but I'm not sure how to do that, because even if I script a new object to be created, I would have to have some way of calling the schedule function on that object. I don't know how to do that, because as far as I know, datablocks can't call functions, correct?
So I made a RainScheduler trigger, which, upon entry, schedules for a new Rain object to be created. In the function that creates the rain, another function is scheduled to delete the Rain object. So far, the rain is created and starts fine, but my echo message that says "scheduler entered" never shows up, and the function that destroys the rain never gets entered. Here's the weird thing: if I take out the code where I create the rain and recompile, the rain still shows up! Shouldn't it have not appeared if I took it out?
So my questions are:
1) How can I create an object on startup that automatically calls a function?
2) If my rain creator function creates the rain, but the echo message that should show up upon function entry doesn't show up, how is the rain being created?
3) Why does the rain show up even when I take that datablock out?
Please forgive me if I'm asking a dumb question or missing something totally obvious. Thank you kindly :)
Here's my code:
$raintriggered = false;
datablock TriggerData(RainScheduler)
{
tickPeriodMS = 4000;
};
function RainScheduler::onEnterTrigger( %this, %trigger, %obj )
{
if(!$raintriggered)
{
$raintriggered = true;
echo("rain scheduled."); //this message does show up, and a few seconds later rain starts
schedule(4000, 0, "startRain");
}
}
function startRain()
{
echo("rain scheduler entered."); //this message never shows up in the console
%raining = new Precipitation(rain) { //this rain object is created successfully
position = "460.193 -544.339 143.145";
rotation = "1 0 0 0";
scale = "1 1 1";
nameTag = "rain";
dataBlock = "HeavyRain";
minSpeed = "1.5";
maxSpeed = "2";
minMass = "0.75";
maxMass = "0.85";
maxTurbulence = "0.1";
turbulenceSpeed = "0.2";
rotateWithCamVel = "1";
useTurbulence = "0";
numDrops = "5000";
boxWidth = "200";
boxHeight = "100";
doCollision = "1";
};
schedule(100000, 0, "endRain", %raining);
}
function endRain(%raining)
{
%raining.delete();
schedule(4000, 0, "startRain");
}
function RainScheduler::onLeaveTrigger( %this, %trigger, %obj )
{
}
function RainScheduler::onTickTrigger(%this, %trigger)
{
}
This is my first time post. Pleased to meet you all :) I'm new to Torque programming, so I'm probably making an obvious mistake here and not realizing it. Here's what I'm trying to accomplish: upon loading my mission, I want an object that schedules rain to start and stop at random times. What I originally wanted was for the object to be created and initialized from the start without any user input, but I'm not sure how to do that, because even if I script a new object to be created, I would have to have some way of calling the schedule function on that object. I don't know how to do that, because as far as I know, datablocks can't call functions, correct?
So I made a RainScheduler trigger, which, upon entry, schedules for a new Rain object to be created. In the function that creates the rain, another function is scheduled to delete the Rain object. So far, the rain is created and starts fine, but my echo message that says "scheduler entered" never shows up, and the function that destroys the rain never gets entered. Here's the weird thing: if I take out the code where I create the rain and recompile, the rain still shows up! Shouldn't it have not appeared if I took it out?
So my questions are:
1) How can I create an object on startup that automatically calls a function?
2) If my rain creator function creates the rain, but the echo message that should show up upon function entry doesn't show up, how is the rain being created?
3) Why does the rain show up even when I take that datablock out?
Please forgive me if I'm asking a dumb question or missing something totally obvious. Thank you kindly :)
Here's my code:
$raintriggered = false;
datablock TriggerData(RainScheduler)
{
tickPeriodMS = 4000;
};
function RainScheduler::onEnterTrigger( %this, %trigger, %obj )
{
if(!$raintriggered)
{
$raintriggered = true;
echo("rain scheduled."); //this message does show up, and a few seconds later rain starts
schedule(4000, 0, "startRain");
}
}
function startRain()
{
echo("rain scheduler entered."); //this message never shows up in the console
%raining = new Precipitation(rain) { //this rain object is created successfully
position = "460.193 -544.339 143.145";
rotation = "1 0 0 0";
scale = "1 1 1";
nameTag = "rain";
dataBlock = "HeavyRain";
minSpeed = "1.5";
maxSpeed = "2";
minMass = "0.75";
maxMass = "0.85";
maxTurbulence = "0.1";
turbulenceSpeed = "0.2";
rotateWithCamVel = "1";
useTurbulence = "0";
numDrops = "5000";
boxWidth = "200";
boxHeight = "100";
doCollision = "1";
};
schedule(100000, 0, "endRain", %raining);
}
function endRain(%raining)
{
%raining.delete();
schedule(4000, 0, "startRain");
}
function RainScheduler::onLeaveTrigger( %this, %trigger, %obj )
{
}
function RainScheduler::onTickTrigger(%this, %trigger)
{
}
About the author
#2
I'm looking in to the OnClientEnterGame suggestion now. That would be great if I could get it to work from there, so thanks for the advice!
Regarding the other problem, I'm pretty sure I'm editing the right file. I checked the console log and everything to see what files were loading. And when I took out the command to execute that particular script in game.cs, the rain didn't show up at all, as expected. So I'm really not sure what's going on with that...back to the drawing board ;)
12/09/2007 (9:07 am)
Thanks Steve :)I'm looking in to the OnClientEnterGame suggestion now. That would be great if I could get it to work from there, so thanks for the advice!
Regarding the other problem, I'm pretty sure I'm editing the right file. I checked the console log and everything to see what files were loading. And when I took out the command to execute that particular script in game.cs, the rain didn't show up at all, as expected. So I'm really not sure what's going on with that...back to the drawing board ;)
#3
which may be where you would like to kick off your timer.
That's where the AIManager is kicked off as well - AIManager.think()
12/09/2007 (10:43 am)
There is a function called startGame() in server/scripts/game.cs,which may be where you would like to kick off your timer.
That's where the AIManager is kicked off as well - AIManager.think()
#4
12/09/2007 (3:51 pm)
When you edit a script, make sure you delete it's .dso file or it may be using it instead of recompiling the new .cs
#5
Game Manager with Time and Weather
12/09/2007 (5:24 pm)
The following resource might give you some good ideas.Game Manager with Time and Weather
#6
Mike...I tried deleting the .dso file, but I got the same error :(
Dunsany....Thanks for that link.
I'm going to work more on these suggestions when I get home tonight :) Thanks everyone!
12/10/2007 (12:48 pm)
Orion....I know exactly where you're talking about. I'll check it out and see if I can kick my timer off from there rather than from a trigger.Mike...I tried deleting the .dso file, but I got the same error :(
Dunsany....Thanks for that link.
I'm going to work more on these suggestions when I get home tonight :) Thanks everyone!
#7
Thanks again everyone!
12/11/2007 (6:17 am)
Okay, here's what the problem was. Apparently, there's a built-in Torque function called startRain, which I did not know about. So when I thought I was calling my function, it was calling something else. Steve D, you were on the right track. Dunsany, the link you posted helped me figure this one out.Thanks again everyone!
Torque Owner Steve D
As far as the other problems, I suspect that since the echo isn't showing up and the rain still happens when you take it out is that you are editing the wrong file? Perhaps there is another file you created by accident and the script is calling that one instead?