Newbie question about arrays
ondrovic
Posts: 217
I haven't really used arrays that much for tracking information but here is what I would like to do. Any ideas would be great:
I am writing code to do the Party Mode on an ADA Suite 16 digital ( not using amx module too bloated ) any way I want to create an array for the 4 different party modes and based on which mode is selected it will tell you which rooms are currently in that preset via feedback on the touch panel. There are 23 rooms that might be apart of that array.
Thanks
Chris
I am writing code to do the Party Mode on an ADA Suite 16 digital ( not using amx module too bloated ) any way I want to create an array for the 4 different party modes and based on which mode is selected it will tell you which rooms are currently in that preset via feedback on the touch panel. There are 23 rooms that might be apart of that array.
Thanks
Chris
0
Comments
Thanks
// This shows how you can have four party modes in the same room.
// In order to continue to use a two dimensional array, you must clear the other party modes when you change one.
// Party 1, Room 1
strParty_Status[1][1] = 1;
// Party 2, Room 1
strParty_Status[2][1] = 1;
// Party 3, Room 1
strParty_Status[3][1] = 1;
// Party 4, Room 1
strParty_Status[4][1] = 1;
// All clear except for party mode 1
// Party 1, Room 1
strParty_Status[1][1] = 1;
// Party 2, Room 1
strParty_Status[2][1] = 0;
// Party 3, Room 1
strParty_Status[3][1] = 0;
// Party 4, Room 1
strParty_Status[4][1] = 0;
// Using a single dimensional array makes more sense. When you set the party mode, you can only have one active party mode per room.
// Room 1, Party mode 1
strParty_Status[1] = 1;
// Room 1, Party mode 2
strParty_Status[1] = 2;
// Room 1, Party mode 3
strParty_Status[1] = 3;
// Room 1, Party mode 4
strParty_Status[1] = 4;
// Room 1, Party mode none
strParty_Status[1] = 0;
Here is the whole workspace
Thanks
dvPanel_25a = 10024:1:1 /// Port 1 Touch Panel
DEFINE_VARIABLE
DEV dvADA_Array[]= {dvPanel_24a, dvPanel_25a}
Because both dvPanel_24a and dvPanel_25a are the same address, the button event is actually tripping twice. Resetting your variable on the second trip... Still think your overcomplicating this with a two dimensional array.
You should also be checking to make sure these variable that you are using to access index of these arrays are not zero or greater then max_length_array, especially if they are set in another button_event/
IF (nParty_Setup >= 1 && nParty_Setup <= MAX_LENGTH_ARRAY(nParty_Status))
{
If(nParty_Status[nParty_Setup][nButton] >= 1)
nParty_Status[nParty_Setup][nButton] = 0
Else
nParty_Status[nParty_Setup][nButton] = 1
/// Note : Flag always resets to 0; because its looking at nParty_Setup once selected is always >=1; need to add a different variable
}
// This line is giving you a runtime error, because you set nParty to Zero, next button_event causes the runtime error.
[dvADA_Array,nParty_Room_Buttons[nButton]] = (nParty_Status[nParty][nButton]) //- not working
nParty = 0
I think you need to change the feedback to be:
ON[dvADA_Array,nParty_Setup_Buttons[nParty_Setup]]
If you don't, the mutually exclusive statement won't take effect. (see technote: http://amx.com/techsupport/techNote.asp?id=757 )
I think there may also be some problems with referencing arrays. Why are you setting nParty = 0 at the end? If this gets activated again, it will cause problems with the array reference being 0.
You can check for these types of errors by enabling internal diagnostics and watch for errors while you push the buttons. Another tool to use is the debugger. Set some break points where you are having problems and then add the variables being used in that section to the watch list. This will let you see if the variables contain the values they should.
Jeff
You should not use Volatile in Local_Var and Stack_Vars
// Wrong
Local_Var Volatile Integer nTest;
// Correct
Local_Var Integer nTest;