HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Randomized weather effects

10-28-2005, 03:59 AM#1
Taelrie
Well I have been trying to puzzle this out but so far no luck. So far the only action I can find to do it is "enable weather effect _______". while this isn't bad on its own, there is over 50 weather effects. Now here comes the real kicker: you cannot assign weather effects to a variable. This means that I can't assign weather effects to a variable then do a random array number. So being the brilliant person I am, I made a weather type variable (there is a weather type variable, but there is no option to set certain weather effects in it so it makes it rather useless), got the reference letters for the weather effects and converted it to JASS then tried to set the veriable using jass. it gets a compiler error. So my question is, is there any wya to set weather effects to a variable?

BTW yes I could make about 50-some if/else statemnts, but the memory leaks involved would probably crash the tragger and maybe the game.
10-28-2005, 05:36 AM#2
The__Prophet
Use a Integer array. So it would look somthing like this:
Collapse JASS:
local integer array WeatherEffect
set WeatherEffect[1] = 'LRaa' //Rays of Sunlight
set WeatherEffect[2] = 'RAhr'//Heavy Rain
ect ect then simply run your trigger like so
Collapse JASS:
call AddWeatherEffect(GetPlayableMapRect(), WeatherEffect[GetRandomInt(1,2)])
10-28-2005, 06:14 AM#3
Anitarf
Of course, it's a waste to always have to initialize a local array, just define a global one.
10-28-2005, 04:30 PM#4
Taelrie
Quote:
Originally Posted by The__Prophet
Use a Integer array. So it would look somthing like this:
Collapse JASS:
local integer array WeatherEffect
set WeatherEffect[1] = 'LRaa' //Rays of Sunlight
set WeatherEffect[2] = 'RAhr'//Heavy Rain
ect ect then simply run your trigger like so
Collapse JASS:
call AddWeatherEffect(GetPlayableMapRect(), WeatherEffect[GetRandomInt(1,2)])

Wouldn't that get a compiler error as well? you are trying to put strings (the reference) into an integer variable. if you were going to do that wouldn't you have to use a string variable?
10-28-2005, 04:50 PM#5
iNfraNe
'blabla' isnt a string. "blabla" would be a string. This is valid.
10-28-2005, 08:46 PM#6
The__Prophet
Quote:
Of course, it's a waste to always have to initialize a local array, just define a global one.

local variables are almost always better than global variables. The only time a global variable should be used is when you need to store data between functions and you dont care about multi instanceability, in which case you should use handle variables.
10-28-2005, 09:17 PM#7
iNfraNe
sorry for offtopic. But doesnt setting a variable take time?
then wouldnt it be faster to store these things (being constants anyway...) in globals since that would save time? (althought in this case locals might be better cause its not called alot and it doesnt need to be kept in memory)
10-28-2005, 10:27 PM#8
The__Prophet
You have to set the variable no matter what. Setting udg_WeatherEffect[1] = 'RAhr' is hardly different than setting WeatherEffect[1] = 'RAhr' The only thing that would be different would be you wouldn have to put local integer array WeatherEffect line during the start of the trigger, instead of a global variable which is created during map initiailization.
10-29-2005, 12:58 AM#9
Vexorian
declaring a local array will be allocating some 8192*4 bytes each time, instead if you always used a global the memory would always be there instead of allocating everytime.

Some times globals are better than locals, specially when there is no need for the variables to be local, the arrays always have the same value and there is no need to let them be independ for each instance of the function