Home AMX User Forum NetLinx Studio

Recalling Structure elements with for loops

I am trying to send multiple 232 strings to a lighting device in order to send a preset where there are a total of 4 loads to control. I am however having a problem with my structure elements, and I think it's how I created/named my structures. Basically, I have 4 zones that I am trying to recall by using a FOR loop, and because of (I believe) how I created the structure, I don't think it will ever work. I've got a total of 2 Structures:
STRUCTURE _Light  //light load setting structure
{
	INTEGER nIntensity  
	INTEGER nFadeTime  
}

STRUCTURE _LightPresets  //structure to call 4 zones of lighting loads
{
	CHAR sPresetName[15]  
	
	_Light nZone1  
	_Light nZone2	 
	_Light nZone3  
	_Light nZone4  
}
And I then create 5 instances of the Presets Structure:
DEFINE_VARIABLE
PERSISTENT _LightPresets uLightPresets[5] //5 presets to store lighting
This way, I have 5 instances, each with a name, 4 zones, and in each zone, 2 integers for storing current level and fade time. My problem comes in when I am trying to send a string using a for loop, like so:
BUTTON_EVENT[dvTPLight,30  //this is merely for testing purposes at this point
{
	PUSH:
	{
		local_var integer i
		FOR(i=1;i<=4;i++)
		{
			SEND_STRING dvLight, "'FADEDIM,',itoa(uLightPresets[1].nZone(i).nIntensity),',[1:1]',$0D,$0A"
			SEND_STRING 0, "'FADEDIM,',uLightPresets[1].nZone(i).nIntensity,',[1:1]',$0D,$0A"
		}
I am sending the string twice, once to the device and again to device 0, again, for debugging purposes. When I try to compile, I get this message:
ERROR: RSB, Rev2.axs(811): C10235: Symbol [NZONE] is not a member of STRUCTURE [_LIGHTPRESETS]  
I understand that the compiler doesn't like that I am trying to call a structure element with a variable, since the structure element in question is not already part of an array, in which case, I think it would work fine. How can I adjust my structure to allow for this type of coding? I was working on something like this, but couldn't get it working, since I can't specify values in the DEFINE_TYPE section:
DEFINE_TYPE
STRUCTURE _Light  //light load setting structure
{
	INTEGER nIntensity  
	INTEGER nFadeTime  
}
STRUCTURE _Zone //light zone holds a single _Light Structure
{
	_Light nZoneLight  
}
STRUCTURE _LightPresets  //structure to call 4 zones of loads
{
	CHAR sPresetName[15]  //15 bytes
	_Zone[4] = {1,2,3,4}
}
Ultimately, my structure needs to look like this:
5 arrays, each with a name, 4 zones, and lights in each zone with intensity and fade time values.
I feel like the for loop will provide me with the ability to expand this to however many presets I need, so that's why I'm trying to use it. Thanks.

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    vegastech wrote: »
    			SEND_STRING dvLight, "'FADEDIM,',itoa(uLightPresets[1].nZone(i).nIntensity),',[1:1]',$0D,$0A"
    

    As the compiler says, you cannot substitute part of a variable name with ()... these generally denote a function call, or indicate execution order when doing math.

    Try this:
    STRUCTURE _Light  //light load setting structure
    {
    	INTEGER nIntensity  
    	INTEGER nFadeTime  
    }
    
    STRUCTURE _LightPresets  //structure to call 4 zones of lighting loads
    {
    	CHAR sPresetName[15]  
    	
    	_Light nZone[4] 
    }
    DEFINE_VARIABLE
    PERSISTENT _LightPresets uLightPresets[5] //5 presets to store lighting
    
    
    BUTTON_EVENT[dvTPLight,30  //this is merely for testing purposes at this point
    {
    	PUSH:
    	{
    		local_var integer i
    		FOR(i=1;i<=4;i++)
    		{
    			SEND_STRING dvLight, "'FADEDIM,',itoa(uLightPresets[1].nZone[i].nIntensity),',[1:1]',$0D,$0A"
    			SEND_STRING 0, "'FADEDIM,',uLightPresets[1].nZone[i].nIntensity,',[1:1]',$0D,$0A"
    		}
    

    That should work.

    Jeff

    P.S.
    There is a chance that you can flood the communication lines with this and lock-up or drop messages. You could move to a timeline or create a queue if this becomes a problem.
  • vegastechvegastech Posts: 369
    Thanks Jeff, that worked! I had tried that previously, but when I was looking at my status tab, I guess I was thinking the error I got "that time" was due to the structure element, when in fact, it had everything to do with the values I specified under define_start, which obviously were no longer valid.
Sign In or Register to comment.