![]() |
Randomising missions
I'm trying the write a script to randomise mission parameters in the "MAIN" section of the mission file; time, weather, cloud height, wind etc. Here's what I have, but it does not work, can anyone help out please?
code removed by author |
Hi, first of all the "GamePlay.gpLoadSectionFile(fileName);" doesn't load the mission file into the game engine. It only creates a ISectionFile object that allows to read/write a mission file with the script and do some changes (like you are already do).
To post load a mission file into the running battle you need to call "GamePlay.gpPostMissionLoad(fileName);" However I don't think it's possible to change the MAIN parameters by a mission file that is post loaded into a running battle. Anyhow your script should look something like this: Code:
using System; |
The script compiles without errors in the FMB compiler. When I run the mission, I get 2 outcomes in about 50/50 proportion:
(1) mission load & runs OK & time/weather is random :) :) :) (2) mission load fails & I get an "object reference not set to an instance of an object" error dialog window. |
Here's a working (beta) of a script to randomise mission time/cloud height/weather/breeze & thermals. Feedback is very welcome.
code removed by author |
More concise and economical way to generate random numbers:
Code:
internal ISectionFile RandomiseMission() |
Quote:
|
Here the main idea: do not create an object of Random anew for each use. One would be enough.
|
Quote:
code removed by author |
No, code "return Random(result).Next(min, max);" is syntactic error for C# compiler, because keyword new required.
I saying, you can remove NextInt function completely. Then create single instance of Random class in the RandomizeWeather function, and then use it as many times as you like, as in my example above. |
Quote:
Line below creates instance of Random class, and assigns the value to variable named random. var random = new Random(Environment.TickCount); Now, we can call method "Next" any number of times: int randomNumber = random.Next(min, max); |
All times are GMT. The time now is 01:59 PM. |
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2007 Fulqrum Publishing. All rights reserved.