Home AMX User Forum NetLinx Studio

array of variables, is it allowed?

i'd really like my code to look like this:

define_variable
persistent integer vol1
...
persistent integer vol8

integer vollevel[] = {vol1,vol2,vol3,vol4,vol5,vol6,vol7,vol8}

define_event
button_event[ndvkp,nMute]
{
push:
{
case nMute:
{
if([button.input.device,nmute])
{
integer vol
vol = vollevel[get_last(ndvkp)]
send_string dvDAS,"'MSVL',itoa(get_last(ndvkp)),',',itoa(vol),10"
}
else
{
send_string dvDAS,"'MSVL',itoa(get_last(ndvkp)),',101',10"
}
}
}
}

I tried and it says 'Initializer is not a constant', Is it just not possible or am I missing something here?

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    What you are trying to do is create an array of pointers. I am not aware of any way to accomplish this in NetLinx.

    I don't think you should have any problem tho in just doing this:
    define_variable
    persistent integer volLevel[8]
    
    define_event
    button_event[ndvkp,nMute]
    {
    push:
    {
    if([button.input.device,nMute])
    {
    integer vol
    vol = vollevel[get_last(ndvkp)]
    send_string dvDAS,"'MSVL',itoa(get_last(ndvkp)),',',itoa(vol), 10"
    }
    else
    {
    send_string dvDAS,"'MSVL',itoa(get_last(ndvkp)),',101',10"
    }
    }
    }
    }
    
    

    I think that should work. Make sure that somewhere, you are turning the nMute channel on when the volume is muted tho.



    Jeff
  • PhreaKPhreaK Posts: 966
    As Jeff pointed out if you've got a group of similar variable you can encapsulated them in a single variable array. However if they are different variables (different types of if you want more descriptive names) you may be better of using a structures to keep things organized.
    DEFINE_TYPE
    
    STRUCTURE _sZones
    {
        INTEGER nLobby
        INTEGER nConferenceRoom
        INTEGER nPassageWay
    }
    
    STRUCTURE _sAudio
    {
        _sZones uVolume
        _sZones uActive
        _sZones uSource
    }
    
    STRUCTURE _sVision
    {
        _sZones uSource
        ..
    }
    
    STRUCTURE _sSystemStatus
    {
        _sAudio uAudio
        _sVision uVision
        ..
    }
    
    DEFINE_CONSTANT
    
    // AV Sources
    DVD = 1
    STB = 2
    MEDIA_SERVER = 3
    // .. etc
    
    DEFINE_VARIABLE
    
    PERSISTENT _sSystemStatus uSystemStatus
    


    With all that defined you can start referencing this in a bit of a neater way. For example the volume for a specific zone would be uSystemStatus.uAudio.uVolume.nLobby. Using structures may appear to take up more lines initially but I find it tends to make expansion, modification and intelligibility a hell of a lot easier. Using the above example, say they've had this current system going and decided they now want AV on their balcony, variable wise you'd just have to add another variable to you _sZones structure and it will cascade down through all the child structures without you need to declare nBalconyVol, nBalconyMute, nBalconyActive, nBalconyVisionSource, nBalconyAudioSource etc. It basically just gives you a much neater way to encapsulate everything. Additionally for debugging all you need to do is monitor your top most parent structures and you'll be able to browse all you tracking variable in a pretty logical manner.

    </rant>
  • Thank you for your reply. Actually the project is done, but I believe there has to be a simpler solution that to create a button event for every keypad used. Now I can squeeze up those codes from 330 lines or something to just 35 lines, most of them just curly brackets.
  • ericmedleyericmedley Posts: 4,177
    Couldn't you just do
    persitent integer vol[10]
    
    

    ?
  • ericmedley wrote: »
    Couldn't you just do
    persitent integer vol[10]
    
    

    ?

    yes I can, I just don't know about it until now. No other soul here speaks Netlinx. Thanks to your replies, now I know.
  • ericmedleyericmedley Posts: 4,177
    No other soul here speaks Netlinx.

    ???
    I don't think this is the case... Most forum members here are pretty versed in it. If I missed the joke please forgive. I'm pretty slow that way sometimes.
  • ericmedley wrote: »
    ???
    I don't think this is the case... Most forum members here are pretty versed in it. If I missed the joke please forgive. I'm pretty slow that way sometimes.

    I mean here in Indonesia. That's why I love this forum.
  • ericmedleyericmedley Posts: 4,177
    I mean here in Indonesia. That's why I love this forum.

    See, that's what I mean about me being slow. I didn't get that...
Sign In or Register to comment.