Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions

Any idea about this ??

Hi Experts,

I really need your help in this one ...

I have created a module and it has a persistence string array. In mainline I have created two instance of same module. But It doesnt create two separate instance of a persistence string array. When one instance modify that array it also affect array in another instance.

I hope you guys understand from this what I mean to say.

What I want to do is when I create two instance of a module I must have two sets of variable which doesnt clash with each other. And that value has to be persistence ...

Anyone did this before?

Thanks in advance.

Comments

  • glr-ftiglr-fti Junior Member Posts: 286
    How about a multi dimension array?

    If you started with

    Persistent Char sVar[1][2]

    make it

    Persistent Char sVar[3][1][2]

    When you call the module pass along the reference for which array you want to update. Fill in the size of each dimension to what you need.
  • DHawthorneDHawthorne Old Timer Posts: 4,584
    Modules do not support persistent variables. If you need a persistent variable in a module, you have to declare it in the main program and pass it as a parameter. So you will need a separate variable for each of your modules. I generally do this as a multi-level array to keep them all in one spot.
  • kbeattyAMXkbeattyAMX Junior Member Posts: 358
    DHawthorne wrote: »
    Modules do not support persistent variables. If you need a persistent variable in a module, you have to declare it in the main program and pass it as a parameter. So you will need a separate variable for each of your modules. I generally do this as a multi-level array to keep them all in one spot.

    I beg to differ. I just changed a value of persistent Variable in one of my modules and rebooted my chassis and that value was still in there.
  • Dan ColegroveDan Colegrove Junior Member Posts: 39
    From my experience modules will not except persistent variables but they will except non-volatile variables. if you change a variable to persistent in a module it is treated like a non-volatile variable which means that after a reboot it will maintain its value but after a download and reboot it will not.

    At least that is how I understand it.
  • kbeattyAMXkbeattyAMX Junior Member Posts: 358
    Just reloaded the code and the value that I gave it is still there.
    I took off the persistence in the module and now when I load the code the value goes to 0.
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    DHawthorne wrote: »
    Modules do not support persistent variables. If you need a persistent variable in a module, you have to declare it in the main program and pass it as a parameter. So you will need a separate variable for each of your modules. I generally do this as a multi-level array to keep them all in one spot.
    kbeattyAMX wrote: »
    I beg to differ. I just changed a value of persistent Variable in one of my modules and rebooted my chassis and that value was still in there.
    I beg to differ your beg to differ. :) Dave is correct, modules do not support persistent variables.
  • kbeattyAMXkbeattyAMX Junior Member Posts: 358
    Okay... On just a code reload, you do not loose the value in a nonvolatile or a persistent variable but if you recompile the code and load it you loose the value in the persistent and nonvolatile. I was just reloading the code without recompiling. If a persistent is defined in the main code then the value persists as long as its definition remains the same.

    I've not had the need to keep variable values after a recompile.
  • microchip78microchip78 Junior Member Posts: 25
    Can you pass custom type in Module

    Can we pass custom type in to Module ...
    DEFINE_TYPE
    
    STRUCTURE IRFUNC
    {
    	CHAR Name[10];
    	INTEGER No;
    	INTEGER Code;
    }
    

    I have designed this structure and want to pass it in to Module but It is giving me an error saying that invalid syntax and pointing it to module definition.

    How can I do this ?? Structure is defined in mainline source file ...
  • kbeattyAMXkbeattyAMX Junior Member Posts: 358
    Sorry, no user defined types are allowed. What your purpose for using a structure?
  • Joe HebertJoe Hebert Junior Member Posts: 2,159
    Can we pass custom type in to Module ...

    How can I do this ?? Structure is defined in mainline source file ...
    You can , but you have to use the encode/decode method described below. Others will tell you to bust the structure up and pass in the elements which is certainly one way to do it but I prefer the encode/decode method. To each their own.

    http://amxforums.com/showpost.php?p=23920&postcount=21
  • ericmedleyericmedley Senior Member - 4000+ posts Posts: 4,177
    Can we pass custom type in to Module ...
    DEFINE_TYPE
    
    STRUCTURE IRFUNC
    {
    	CHAR Name[10];
    	INTEGER No;
    	INTEGER Code;
    }
    

    You can per se. There's a way to do it. However, here's the prescribed one. the other is just fine.

    Here's what it would probably look like.

    main program
    DEFINE_VARIABLE
    Persistent CHAR Name[10]
    Persistent INTEGER No
    Persistent INTEGER Code
    
    DEFINE_MODULE 
    
    DEFINE_MODULE 'Your_module_name' yourmodule_1
    			    (Name,
    			    No,
    			    Code
    			    )
    
    

    and then over in the top of the module file...
    MODULE_NAME='Your_module_name' '
    (
    From_Main_Name[10],
    From_Main_No
    From_Main_Code
    )
    
    

    In the module, you use the 'From_Main_abc' variables as they will hold the values from the main program.

    Hope that helps.
  • DHawthorneDHawthorne Old Timer Posts: 4,584
    kbeattyAMX wrote: »
    Okay... On just a code reload, you do not loose the value in a nonvolatile or a persistent variable but if you recompile the code and load it you loose the value in the persistent and nonvolatile. I was just reloading the code without recompiling. If a persistent is defined in the main code then the value persists as long as its definition remains the same.

    I've not had the need to keep variable values after a recompile.

    That is the defined difference. Non-volatile persist after a reboot, persistent persists after a reload. The time you want a full persistent variable is when it is storing user settings (like thermostat setbacks) that you don't want lost every time the master gets an update.
Sign In or Register to comment.