| 12-05-2007, 05:36 PM | #1 |
Although this is probably covered in the JASS Helper Manual, I couldn't find/understand it with my limited knowledge. Below is the triggers I use; both untested. I'm to busy to take the time to do some testing today, two tests and appointments, and I wanted to know the correct answer. --- Instead of using globals, which require longer names to prevent overlaps with other systems, I wanted to use one struct which was global; that would be accessible by all functions, would be changeable (not constant, but this one can be). If I make a struct inside a function "local Items ip=Items.create()", would it be accessible only from within that function, that one time, or would it be accessible again, presuming I didn't destroy it. Recap: Struct = global; any function can use. If anything else is needed ask, and I'll reply as soon as a can. Busy day today. JASS:scope Items globals string array I_Name //Just the name string array I_Info //Extra information; a description string array I_Path //The file path of the model integer array I_Code //The code for the item. Ex: 'I00O' constant integer I_NOM = 1//Number of items endglobals //Setup to run on map initilization function InitTrig takes nothing returns nothing set I_Name[1] = "Water Blade" set I_Info[1] = "A water elemental blade, giving plus to all water based attachs and abilities. Highly effective against fire elementals." set I_Path[1] = "war3mapImported\\NSRPG_sword_waterblade.mdl" set I_Code[1] = 'I00O' endfunction endscope JASS:scope ItemPickup //All the item information in one struct //Names, description (extra information), path (where the models at), code (item code). //I_NOM is the max number of items struct Items string array n[I_NOM] //Name string array i[I_NOM] //Extra information; description string array p[I_NOM] //Models file path integer array c[I_NOM] //Item code method Item takes nothing returns nothing local integer i = 0 loop set i = i + 1 set .n[i] = I_Name[i] set .i[i] = I_Info[i] set .p[i] = I_Path[i] set .c[i] = I_Code[i] exitwhen i == I_NOM endloop endmethod endstruct private function actions takes nothing returns nothing local Items ip=Items.create() local integer i = 0 call ip.Item() loop set i = i + 1 if GetItemTypeId(GetManipulatedItem()) == ip.c[i] then call AddSpecialEffectTarget(ip.p[i], GetTriggerUnit(), "origin") endif exitwhen i == I_NOM endloop endfunction public function InitTrig takes nothing returns nothing local trigger trig = CreateTrigger() local integer i = 0 //Zero equals player 1 (red). loop //Checks for any unit picking up a item. call TriggerRegisterPlayerUnitEvent(trig, Player(i), ConvertPlayerUnitEvent(49), null) set i = i + 1 exitwhen i == 12 //Max number of players endloop call TriggerAddAction(trig, function actions) endfunction endscope |
| 12-05-2007, 08:47 PM | #2 |
It actually might be easier with a long block of globals (or public or private in a library or scope!), and that isn't what structs are really for... But if you wanted to do it this way, just make a struct like this: struct MyStruct static constant integer IntA static integer IntB static constant real Shoop = 1 static constant string Da = 2 static constant timer Whoop = 3 endstruct You can access the variables with MyStruct.<Variable Name> you dont need to create a new one. |
| 12-06-2007, 12:42 AM | #3 |
Just using a globals block with arrays in them is going to be much easier and make much more sense. |
| 12-06-2007, 02:01 AM | #4 | |
Quote:
I use static structs instead of globals a quite a bit. They give you a nice name space to work with. You also get the option of readonly variables, which are great. |
| 12-06-2007, 02:10 AM | #5 | |
Quote:
Just to make sure, if I use "local <struct name> I" in a function will the variables edited also be changed globally? |
| 12-06-2007, 02:52 AM | #6 | ||
Quote:
Struct=pointer , any function with a reference to it can use it. Quote:
|
