| 01-21-2009, 09:23 PM | #1 |
Anyone have any idea how to set a variable to a function or another variable, so that anytime you call the variable it will update itself by either calling the function or the other variable? Right now I use a function which returns a value (in a string): JASS://Retrives variable data from other triggers/codes and reformat them for multiboard display (string/text) private function Get takes integer id, integer m, integer p returns string local string s if m == 2 then if p == 0 then if Camera_Data.D[id].rotation then set s = "On" else set s = "Off" endif elseif p == 1 then set s = I2S(R2I(Camera_Data.D[id].rotationspeed)) elseif p == 2 then set s = I2S(R2I(Camera_Data.D[id].aoa)) elseif p == 3 then set s = I2S(R2I(Camera_Data.D[id].fov)) elseif p == 4 then set s = I2S(R2I(Camera_Data.D[id].targetdistance)) elseif p == 5 then set s = I2S(R2I(Camera_Data.D[id].zoffset)) elseif p == 6 then set s = I2S(R2I(Camera_Data.D[id].farz)) endif elseif m == 3 then if p == 1 then set s = I2S(R2I(InvisibleDestructables_Radius[id])) elseif p == 2 then set s = I2S(InvisibleDestructables_WhichImage[id]) endif endif if s != null then return s else return "" endif endfunction |
| 01-21-2009, 10:26 PM | #2 |
How is what you have now not adequate? |
| 01-22-2009, 12:55 AM | #3 |
It a mess. Right now its all clumped together and its going to get a whole a lot bigger with other stuff I need to add in. I want to separate the whole thing into individual structs. Each struct needs to know which/what variable to get updated information from. I don't know how to tell it to use which variable or how to make a function call without pre-making it in one large function. If this doesn't make sense sorry. Currently it's a little of a mess (this doesn't work btw): JASS:scope Multiboard initializer Init globals //Constants private constant real ARRROW_KEY_INTERVAL_CHECK = .2 //Almost 3 times a sec private constant real ARROW_KEY_WAIT_FOR_LOOP = .5 private constant string TEXT_POINTER = ">>>" //Self/auto setting variables (you don't need to edit/touch these) private multiboard array Multiboard //Just the boards private integer array Menu //Holds the players menu private integer array Position //and position private boolean array KeyPress[12][4] //Which arrow keys are pressed; True/False; 1=left, 2=right, 3=up, 4=down private boolean array KeyStop[12] //true = up/down doesn't work private integer NumOfMenus private integer array MenuSize[810] //Stores all non-changing text (multiboard type[num of rows/columns], the title, and other text. private integer array Type [10] //1=Info, 2=Pointer/Info, 3=Pointer/Info/Real private string array Title[10] //Title of menu private string array Info [810][10] //What to display for each row endglobals //Just what text to display private function InitText takes nothing returns nothing local integer i = 0 local integer i2 = 0 //Intro menu set Type [0] = 1 set Title[0] = "Intro Menu" set Info [0][0] = "Use the arrow keys to navagate" //Camera Menu set Type [1] = 3 set Title[1] = "Camera Settings" set Info [1][0] = "Rotation On/Off" set Info [1][1] = "Rotation Speed" set Info [1][2] = "Angle of Attack" set Info [1][3] = "Field of View" set Info [1][4] = "Target Distance" set Info [1][5] = "Z Offset" set Info [1][6] = "-Defaults-" set Info [1][7] = "1st Person" set Info [1][8] = "3rd Person" set Info [1][9] = "Birds-eye" //Invisible Destructables set Type [2] = 3 set Title[2] = "Invis. Trees" set Info [2][0] = "Radius" set Info [2][1] = "Image" //Stats menu (auto updating?) set Type [3] = 1 //Should be 2 set Title[3] = "Stats" set Info [3][0] = "Life (HP)" set Info [3][1] = "Mana (MP)" set Info [3][2] = "Strength" set Info [3][3] = "Agility" set Info [3][4] = "Intelligence" loop loop exitwhen Info[i][i2] == null set i2 = i2 + 1 endloop set MenuSize[i] = i2 set i2 = 0 set i = i + 1 exitwhen Type[i] == null endloop set NumOfMenus = i - 1 call BJDebugMsg("text") endfunction //Changes settings of variables outside this trigger/code private function Set takes integer id, integer reverse returns nothing if Menu[id] == 2 then if Position[id] == 0 then if Camera_Data.D[id].rotation then set Camera_Data.D[id].rotation = false else set Camera_Data.D[id].rotation = true endif elseif Position[id] == 1 then //Camera: Rotation speed (time needed to rotate camera) set Camera_Data.D[id].rotationspeed = Camera_Data.D[id].rotationspeed + (.1*reverse) elseif Position[id] == 2 then //Camera: Angle of attack set Camera_Data.D[id].aoa = Camera_Data.D[id].aoa + (2*reverse) elseif Position[id] == 3 then //Camera: Field of view set Camera_Data.D[id].fov = Camera_Data.D[id].fov + (2*reverse) elseif Position[id] == 4 then //Camera: Distance to target (unit) set Camera_Data.D[id].targetdistance = Camera_Data.D[id].targetdistance + (20*reverse) elseif Position[id] == 5 then //Camera: Z Offset (height from/above ground) set Camera_Data.D[id].zoffset = Camera_Data.D[id].zoffset + (2*reverse) elseif Position[id] == 6 then //Camera: Far Z (Camera cut-off distance) set Camera_Data.D[id].farz = Camera_Data.D[id].farz + (50*reverse) elseif Position[id] == 7 then //Preset: 1st person view set Hero_TransparencyOn[id] = true set Camera_Data.D[id].rotation = true set Camera_Data.D[id].rotationspeed = 1 set Camera_Data.D[id].aoa = 355 set Camera_Data.D[id].fov = 20 set Camera_Data.D[id].targetdistance = 240 set Camera_Data.D[id].zoffset = 100 elseif Position[id] == 8 then //Preset: 3rd person view set Hero_TransparencyOn[id] = true set Camera_Data.D[id].rotation = true set Camera_Data.D[id].rotationspeed = 2 set Camera_Data.D[id].aoa = 325 set Camera_Data.D[id].fov = 120 set Camera_Data.D[id].targetdistance = 150 set Camera_Data.D[id].zoffset = 100 elseif Position[id] == 9 then //Preset: Birds-eye set Hero_TransparencyOn[id] = false set Camera_Data.D[id].rotation = false set Camera_Data.D[id].rotationspeed = 2 set Camera_Data.D[id].aoa = 300 set Camera_Data.D[id].fov = 120 set Camera_Data.D[id].targetdistance = 650 set Camera_Data.D[id].zoffset = 175 endif elseif Menu[id] == 3 then if Position[id] == 0 then set InvisibleDestructables_Radius[id] = InvisibleDestructables_Radius[id] + (10*reverse) elseif Position[id] == 1 then set InvisibleDestructables_WhichImage[id] = InvisibleDestructables_WhichImage[id] + (1*reverse) endif endif endfunction //Retrives variable data from other triggers/codes and reformat them for multiboard display (string/text) private function Get takes integer id, integer m, integer p returns string local string s if m == 2 then if p == 0 then if Camera_Data.D[id].rotation then set s = "On" else set s = "Off" endif elseif p == 1 then set s = I2S(R2I(Camera_Data.D[id].rotationspeed)) elseif p == 2 then set s = I2S(R2I(Camera_Data.D[id].aoa)) elseif p == 3 then set s = I2S(R2I(Camera_Data.D[id].fov)) elseif p == 4 then set s = I2S(R2I(Camera_Data.D[id].targetdistance)) elseif p == 5 then set s = I2S(R2I(Camera_Data.D[id].zoffset)) elseif p == 6 then set s = I2S(R2I(Camera_Data.D[id].farz)) endif elseif m == 3 then if p == 1 then set s = I2S(R2I(InvisibleDestructables_Radius[id])) elseif p == 2 then set s = I2S(InvisibleDestructables_WhichImage[id]) endif endif if s != null then return s else return "" endif endfunction //======================================================================================== //Updates various parts of the multiboard (everything, the pointer, and/or the variables (numbers) //======================================================================================== private function PointerUpdate takes integer id returns nothing local multiboarditem mbi local integer row = 0 if Type[Menu[id]] == 3 then //Clears the text for the Pointer part loop set mbi = MultiboardGetItem(Multiboard[id], row, 0) call MultiboardSetItemValue(mbi, "") set row = row + 1 exitwhen row == MenuSize[Menu[id]] endloop //The pointer and title (incase the pointer is on the title) if Position[id] == -1 then if Menu[id] == 0 then call MultiboardSetTitleText(Multiboard[id], " " + Title[Menu[id]] + " >") elseif Menu[id] == NumOfMenus then call MultiboardSetTitleText(Multiboard[id], "< " + Title[Menu[id]] + " ") else call MultiboardSetTitleText(Multiboard[id], "< " + Title[Menu[id]] + " >") endif else call MultiboardSetTitleText(Multiboard[id], Title[Menu[id]]) call MultiboardSetItemValue(MultiboardGetItem(Multiboard[id], Position[id], 0), TEXT_POINTER) endif endif endfunction private function Clear takes integer id returns nothing local integer row = 0 local integer col = 0 loop loop call MultiboardSetItemValue(MultiboardGetItem(Multiboard[id], row, col), "") set col = col + 1 exitwhen col == 3 endloop set row = row + 1 exitwhen row == 10 endloop endfunction private function FullUpdate takes integer id returns nothing local integer row = 0 local integer col = 0 local multiboarditem mbi //call Clear(id) call MultiboardClear(Multiboard[id]) //Resizes the multiboard call MultiboardSetRowCount(Multiboard[id], MenuSize[Menu[id]]) call MultiboardSetColumnCount(Multiboard[id], Type[Menu[id]]) call MultiboardSetItemsStyle(Multiboard[id], true, false) //Applies new text to the multiboard (pointer, text, variables) if Type[Menu[id]] == 1 then //Text only call BJDebugMsg("1.1") loop set mbi = MultiboardGetItem(Multiboard[id], row, 0) call MultiboardSetItemWidth(mbi, .30) //call MultiboardSetItemsWidth(Multiboard[id], .30) call MultiboardSetItemValue(mbi, Info[Menu[id]][row]) set row = row + 1 exitwhen row == MenuSize[Menu[id]] endloop elseif Type[Menu[id]] == 2 then //Text and variables (munbers) call BJDebugMsg("1.2") loop set mbi = MultiboardGetItem(Multiboard[id], row, 0) call MultiboardSetItemWidth(mbi, .30) call MultiboardSetItemValue(MultiboardGetItem(Multiboard[id], row, 0), Info[Menu[id]][row]) set mbi = MultiboardGetItem(Multiboard[id], row, 1) call MultiboardSetItemWidth(mbi, .30) call MultiboardSetItemValue(MultiboardGetItem(Multiboard[id], row, 1), Get(id, Menu[id], row)) set row = row + 1 exitwhen row == MenuSize[Menu[id]] endloop elseif Type[Menu[id]] == 3 then //Point, text, and variables (numbers) call BJDebugMsg("1.3") loop set mbi = MultiboardGetItem(Multiboard[id], row, 0) call MultiboardSetItemWidth(mbi, .30) set mbi = MultiboardGetItem(Multiboard[id], row, 1) call MultiboardSetItemWidth(mbi, .30) call MultiboardSetItemValue(mbi, Info[Menu[id]][row]) set mbi = MultiboardGetItem(Multiboard[id], row, 2) call MultiboardSetItemWidth(mbi, .30) call MultiboardSetItemValue(mbi, Get(id, Menu[id], row)) set row = row + 1 exitwhen row == MenuSize[Menu[id]] endloop endif //The title and Pointer if Position[id] == -1 then if Menu[id] == 0 then call MultiboardSetTitleText(Multiboard[id], " " + Title[Menu[id]] + " >") elseif Menu[id] == NumOfMenus then call MultiboardSetTitleText(Multiboard[id], "< " + Title[Menu[id]] + " ") else call MultiboardSetTitleText(Multiboard[id], "< " + Title[Menu[id]] + " >") endif else call MultiboardSetTitleText(Multiboard[id], Title[Menu[id]]) call MultiboardSetItemValue(MultiboardGetItem(Multiboard[id], Position[id], 0), TEXT_POINTER) endif call MultiboardSetItemsStyle(Multiboard[id], true, false) endfunction //======================================================================================== //For run keys are held/pressed; changes menus/positions/variables //======================================================================================== //Checks if a arrow key is held down and does whatever is normally down (change menu/position/variable) private function KeyLoop takes nothing returns nothing local integer id = 0 local integer i = 0 local integer counter = 0 loop //Checks if more then one key is being held loop set i = i + 1 if KeyPress[id][i] then set counter = counter + 1 endif exitwhen i == 4 endloop if counter == 1 then if KeyPress[id][1] then if Menu[id] > 0 and Position[id] == -1 then //Menu Left set Menu[id] = Menu[id] - 1 if Menu[id] == 0 or Menu[id] == 3 then set KeyStop[id] = true else set KeyStop[id] = false endif call FullUpdate(id) else //Change variable call Set(id, -1) //Changes a variable call FullUpdate(id) endif elseif KeyPress[id][2] then if Menu[id] < NumOfMenus and Position[id] == -1 then //Menu Right set Menu[id] = Menu[id] + 1 if Menu[id] == 0 or Menu[id] == 3 then set KeyStop[id] = true else set KeyStop[id] = false endif call FullUpdate(id) else //Change variable call Set(id, 1) call FullUpdate(id) endif elseif KeyPress[id][3] and Position[id] > -1 and Type[Menu[id]] != 1 and Type[Menu[id]] != 2 and (not KeyStop[id]) then //Position Down set Position[id] = Position[id] - 1 call PointerUpdate(id) elseif KeyPress[id][4] and Position[id] < MenuSize[Menu[id]] and Type[Menu[id]] != 1 and Type[Menu[id]] != 2 and (not KeyStop[id]) then //Position Up set Position[id] = Position[id] + 1 call PointerUpdate(id) endif endif set id = id + 1 exitwhen id == 12 endloop endfunction //For tapping the key and instead of having to wait for the key loop to run (it's faster) private function QuickKey takes integer id, integer key returns nothing local integer i = 0 local integer counter = 0 call BJDebugMsg("1") //Checks if more then one key is being held loop set i = i + 1 if KeyPress[id][i] then set counter = counter + 1 endif exitwhen i == 4 endloop if counter <= 1 then if key == 1 then call BJDebugMsg("2 left") if Menu[id] > 0 and Position[id] == -1 then //Menu Left set Menu[id] = Menu[id] - 1 if Menu[id] == 0 or Menu[id] == 3 then set KeyStop[id] = true else set KeyStop[id] = false endif call FullUpdate(id) //Updates the whole multiboard (all text) else //Change variable call Set(id, -1) //Changes a variable call FullUpdate(id) endif elseif key == 2 then call BJDebugMsg("2 Right") if Menu[id] < NumOfMenus and Position[id] == -1 then //Menu Right set Menu[id] = Menu[id] + 1 if Menu[id] == 0 or Menu[id] == 3 then set KeyStop[id] = true else set KeyStop[id] = false endif call FullUpdate(id) else //Change variable call Set(id, 1) call FullUpdate(id) endif elseif key == 3 and Position[id] > -1 and Type[Menu[id]] != 1 and Type[Menu[id]] != 2 and (not KeyStop[id]) then //Position Down call BJDebugMsg("2 Down") set Position[id] = Position[id] + 1 call FullUpdate(id) //call PointerUpdate(id) elseif key == 4 and Position[id] < MenuSize[Menu[id]] and Type[Menu[id]] != 1 and Type[Menu[id]] != 2 and (not KeyStop[id]) then //Position Up call BJDebugMsg("2 Up") set Position[id] = Position[id] - 1 call FullUpdate(id) //call PointerUpdate(id) endif endif call BJDebugMsg("3") endfunction //======================================================================================== //Pressing/Releasing the arrow keys //======================================================================================== private function Down_Left takes nothing returns nothing call QuickKey(GetPlayerId(GetTriggerPlayer()), 1) set KeyPress[GetPlayerId(GetTriggerPlayer())][1] = true endfunction private function Down_Right takes nothing returns nothing call QuickKey(GetPlayerId(GetTriggerPlayer()), 2) set KeyPress[GetPlayerId(GetTriggerPlayer())][2] = true endfunction private function Down_Down takes nothing returns nothing call QuickKey(GetPlayerId(GetTriggerPlayer()), 3) set KeyPress[GetPlayerId(GetTriggerPlayer())][3] = true endfunction private function Down_Up takes nothing returns nothing call QuickKey(GetPlayerId(GetTriggerPlayer()), 4) set KeyPress[GetPlayerId(GetTriggerPlayer())][4] = true endfunction private function Up_Left takes nothing returns nothing set KeyPress[GetPlayerId(GetTriggerPlayer())][1] = false endfunction private function Up_Right takes nothing returns nothing set KeyPress[GetPlayerId(GetTriggerPlayer())][2] = false endfunction private function Up_Down takes nothing returns nothing set KeyPress[GetPlayerId(GetTriggerPlayer())][3] = false endfunction private function Up_Up takes nothing returns nothing set KeyPress[GetPlayerId(GetTriggerPlayer())][4] = false endfunction //======================================================================================== //Setup //======================================================================================== private function InitBoard takes nothing returns nothing local integer id = 0 loop if GetPlayerController(Player(id)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(id)) == PLAYER_SLOT_STATE_PLAYING then if GetLocalPlayer() == Player(id) then //Different people, different boards call MultiboardMinimize(Multiboard[id], false) call MultiboardDisplay(Multiboard[id], true) endif endif set id = id + 1 exitwhen id == 12 endloop //If arrow key is held down change whatever (menu, position, real/number, etc) //Just like pressing the key normally but it does it again and again call TimerStart(CreateTimer(), ARRROW_KEY_INTERVAL_CHECK, true, function KeyLoop) endfunction private function Init takes nothing returns nothing local trigger t1 = CreateTrigger() local trigger t2 = CreateTrigger() local trigger t3 = CreateTrigger() local trigger t4 = CreateTrigger() local trigger t5 = CreateTrigger() local trigger t6 = CreateTrigger() local trigger t7 = CreateTrigger() local trigger t8 = CreateTrigger() local trigger t9 = CreateTrigger() local integer id = 0 call InitText() loop //Checks that the game-slot is used by a USER and user is PLAYING if GetPlayerController(Player(id)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(id)) == PLAYER_SLOT_STATE_PLAYING then //Multiboard setup set Menu[id] = 0 //Default (Intro Menu) set Position[id] = -1 //Default (Title) set Multiboard[id] = CreateMultiboard() //call MultiboardSetItemsStyle(Multiboard[id], true, false) call FullUpdate(id) //Used by the arrow keys events set KeyPress[id][1] = false //Default; arrow keys are released set KeyPress[id][2] = false set KeyPress[id][3] = false set KeyPress[id][4] = false set KeyStop[id] = false //Pressing the key down call TriggerRegisterPlayerEvent(t1, Player(id), EVENT_PLAYER_ARROW_LEFT_DOWN) call TriggerRegisterPlayerEvent(t2, Player(id), EVENT_PLAYER_ARROW_RIGHT_DOWN) call TriggerRegisterPlayerEvent(t3, Player(id), EVENT_PLAYER_ARROW_DOWN_DOWN) call TriggerRegisterPlayerEvent(t4, Player(id), EVENT_PLAYER_ARROW_UP_DOWN) //Letting go of the key call TriggerRegisterPlayerEvent(t5, Player(id), EVENT_PLAYER_ARROW_LEFT_UP) call TriggerRegisterPlayerEvent(t6, Player(id), EVENT_PLAYER_ARROW_RIGHT_UP) call TriggerRegisterPlayerEvent(t7, Player(id), EVENT_PLAYER_ARROW_DOWN_UP) call TriggerRegisterPlayerEvent(t8, Player(id), EVENT_PLAYER_ARROW_UP_UP) endif set id = id + 1 exitwhen id == 12 endloop call TriggerAddAction(t1, function Down_Left) call TriggerAddAction(t2, function Down_Right) call TriggerAddAction(t3, function Down_Down) call TriggerAddAction(t4, function Down_Up) call TriggerAddAction(t5, function Up_Left) call TriggerAddAction(t6, function Up_Right) call TriggerAddAction(t7, function Up_Down) call TriggerAddAction(t8, function Up_Up) //Makes the multiboard, sets what text to display, and displays the multiboards locally (each player sees a different board) call TriggerRegisterTimerEvent(t9, 1, false) call TriggerAddAction(t9, function InitBoard) endfunction endscope |
| 01-22-2009, 12:22 PM | #4 |
Well, you can't use variables like that. There's no "variable" type, you can't use variables as objects, you can't have a variable that holds another variable if that makes any sense. You either need to store your data in an array and use the index to reference it or you'd need to write an interface/function interface and then for every variable write a struct/function extending that interface that returns that variable. Needless to say, the latter solution is much messier and slower than what you have now. |
