User Tools

Site Tools


macros:example:createreplacegroup

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

macros:example:createreplacegroup [2019/03/09 18:40] (current)
icke_siegen created
Line 1: Line 1:
 +Example
  
 +====== Create/​Replace Group (snippet) ======
 +
 +^ by: | Gregory Haynes, November 2018 |
 +^ published: | http://​forum.avolites.com/​viewtopic.php?​f=20&​t=5938 |
 +^ description:​ | snippet to store a group regardless whether it already exists or not |
 +^ remarks: |  |
 +
 +{{tag>​store replace create group}}
 +
 +The idea was to use ''​Group.StoreGroupReplace(Handles.GetTitanIdFromHandle(...))''​ to record a group regardless whether it already exists or not, but this doesn'​t work.
 +
 +There are distinct functions:
 +  * if a group does not exist then ''​Group.StoreGroup''​ stores the group (but would fail if it already exists)
 +  * if the group already exists then ''​Group.ReplaceGroupOnHandle''​ replaces (but won't if the groups does not exist)
 +
 +>I don't think there is a single function which would do both replacing and storing as in most cases the software will return an error if it cannot do exactly what you have asked rather than make an assumption. What you would probably have to do is determine yourself whether the group already exists and then call the correct function, you should be able to do this using the Group.CheckIfGroupExists function.
 +
 +==== functions ====
 +  * [[:​macros:​function:​Group.CheckIfGroupExists]]
 +  * [[:​macros:​function:​Math.IsEqual]]
 +  * [[:​macros:​function:​Group.ReplaceGroupOnHandle]]
 +  * [[:​macros:​function:​Group.StoreGroup]]
 +
 +==== affected properties ====
 +  * [[:​macros:​property:​Group.Numeric.IsValid]]
 +
 +==== control structures ====
 +  * [[macros:​control_structures|]]
 + 
 +===== Code =====
 +<code xml>
 +<​step>​Group.CheckIfGroupExists(999.0,​ "​Group.Numeric.IsValid"​)</​step>​
 +<step condition="​Math.IsEqual(Group.Numeric.IsValid,​ True)">​Group.ReplaceGroupOnHandle(userNumber:​999)</​step>​
 +<step condition="​Math.IsEqual(Group.Numeric.IsValid,​ False)">​Group.StoreGroup(userNumber:​999)</​step>​
 +</​code>​
 +
 +
 +===== Explanation =====
 +
 +This explains the functional steps within the sequence. For all the other XML details please refer to [[:​macros:​formats_and_syntax#​xml_format|Formats and syntax]]
 +
 +This checks if a particular group already exists, and then calls the correct function to store or replace the group.
 +
 +===== How to use it =====
 +
 +Snippet only, to explain how the functions work. 
 +
 +
 +~~DISCUSSION~~
macros/example/createreplacegroup.txt ยท Last modified: 2019/03/09 18:40 by icke_siegen