List Item Example project for Iridium V2.0

Q:
Is their an good Example out their showing the function of the "List Item". 
I found the example project under the Wiki page. But all comments are in Russian and the project does not have a function that you can actually press on the list items and some action will be executed.
 It would be nice if anyone has a good working example.

A:
Please try this project.

ListTest__2_.irpz

Custom Slider for the Level Item

In iRidium 2.1 you can use a slider from the ready list, available for each Level item. But if want to see your own slider on the Level to make it unique, please see this method.
Download the project from attachment. Here you can see the Level items, Slider items and Script file in [JS] window.  This script connects the Level with the separated Slider.
Using instances of the script you can make one, two or more Levels with unique Sliders.
alternate slider.irpz

3 state button

Need:
- item type = Level, name = Item 1
- item type =  Button, name = Item 2
- script 

1. For Item 1, create 3 states and changes property:

Feedback =  Channel
Min: 0
Max: 2


2. Item 2, for all state change property color alpha channel = 0;


3. open script editor (JS button)

4. create script

IR.AddListener(IR.EVENT_ITEM_RELEASE, IR.GetItem("Page 1").GetItem("Item 2"), function(){
   var item =  IR.GetItem("Page 1").GetItem("Item 1");
   item.Value = (item.Value + 1) % 3;      

   switch( item.Value )
   {
     case 0:
     // Commands
     break;

     case 1:
     // Commands
     break;

     case 2:
     // Commands
     break;
    }
});

3State_Buttons_2.irpz

Javascript Tutorials

Hi 

There 6 hours of tutorials going over the basics of Javascript.  Keep in mind that in some cases they will explain syntax which is unique to using Javascript in a browser.

https://www.youtube.com/playlist?feature=edit_ok&list=PLGJDCzBP5j3xKdHn-RYHvk3uafZSN0eYV">https://www.youtube.com/playlist?feature=edit_ok&list=PLGJDCzBP5j3xKdHn-RYHvk3uafZSN0eYV

thanks,


Roger

Rotate letters for language Hebrew


function RotateText(){
   for(var j = 2; j < IR.PagesCount; j++)
      for(var i = 0; i < IR.GetPage(j).ItemsCount; i++)
      {  
         var string = IR.GetPage(j).GetItem(i).GetState(0).Text;
         if(string.charCodeAt(0) > 122){     
            IR.GetPage(j).GetItem(i).GetState(0).Text = "";
            for(var k = string.length; k >= 0; k--){
                IR.GetPage(j).GetItem(i).Text += string.charAt(k);
    
            }     
          }    
      }
   for(var j = 0; j < IR.PopupsCount; j++)
      for(var i = 0; i < IR.GetPopup(j).ItemsCount; i++)
      {  
         var string = IR.GetPopup(j).GetItem(i).GetState(0).Text;
         if(string.charCodeAt(0) > 122){
            IR.GetPopup(j).GetItem(i).GetState(0).Text = "";
            for(var k = string.length; k >= 0; k--){
                IR.GetPopup(j).GetItem(i).Text += string.charAt(k); 
            }  
          }       
      }
}
IR.AddListener(IR.EVENT_START,0,RotateText);

RotateText.irpz

Change a text at Item when Level moves

This example shows you how to change some parameter of the graphic item in your GUI.

We change a text field of the item from the word to the real value received from equipment and back. It is possible using tags of graphic item.


ChangeText-when-lvl-moves.irpz

Open the popup when maximizing the app

If you want to open some default page or popup each time when maximizing the iRidium app, use the example attached


Background-Foreground_mode_iOS.irpz

Color relation

Q:
I use a color picker to fill a global token. But if I use the editor to create a relation it doesn't work.

Imagehttp://farm9.staticflickr.com/8123/8659810061_9308ffd90e_z.jpg">

If I use Javascript using the following line:
IR.GetItem("Main").GetItem("Item 1").GetState(0).FillColor = IR.GetVariable("Tokens.BannerColor");
It DOES work. But it would be nice if i could use the first option

A:
This  fixed! Please try project!




ColorTest__1_.irpz

EVENT_ITEM_CHANGE not send text value

Q:
I have a project with:
 - 1 Page with name "Eventi"
 - 4 EditBox with name in page
 - 1 Sound with name "beep.wav"

I need play a sound when text property of one item change and text is "1".
I write in JS this code


var Eventi;

IR.AddListener(IR.EVENT_START, 0, function()
{
   Eventi = new Alarm();    
});

function Alarm()
{
   var ItemList = ["Item 4","Item 1","Item 2","Item 3"];
   var Page = IR.GetItem("Eventi");
   
   for(i=0;i<ItemList.length;i++)
   {
      IR.Log("Generazione evento item "+ItemList[i]);
      IR.AddListener(IR.EVENT_ITEM_CHANGE, Page.GetItem(ItemList[i]),function (text)
      {
            if(text = "1")
            {
               IR.PlaySound('Alarm.mp3');   
            }
      });
   } 
};


I run this code with some Log istruction and i see that when i change text on the object, the variable "text" in JS is always "undefined".

This is a bug or I wrong something?

A:
Please try this project.

FullAccessDataItemforListener.irpz

Image size changing

Q:

When I have an javascript with:
IR.GetItem("Page 1").GetItem("Button").GetState(0).Image = "pict.jpg"; 
It ads an image to the button.
When I ad:
IR.GetItem("Page 1").GetItem("Button").Width = 500;
IR.GetItem("Page 1").GetItem("Button").Height = 100;
It changes the button size, but not the image size.
How can I change the image size in the javascript? 

A:
You can not change image size with script, but you can change image size with item property "image stetch" = propoptional (or full size).  if property image stetch = prooportional (or full size) then image auto change size after set.
 
 
how change property image stretch? select item, open object properties panel, select tab states and find this property.

Recommended Reading for the Scripts

http://www.w3schools.com/js/default.asp" style="font-size: medium;">http://www.w3schools.com/js/default.asp

The following topics are useful for iRidium Script:
JS Statements JS Comments JS Variables JS Data Types JS Objects JS Functions JS Operators JS Comparisons JS Conditions JS Switch JS Loop For JS Loop While JS Breaks JS Errors JS Validation JS Object JS Number JS String JS Date JS Array JS Boolean JS Math JS RegExp 

You don't need to read the sections JS Libraries, JS HTML DOM, JS Windows; because these are specific topics for using javascript for an web browser.

For JSON take a look at:
http://www.w3schools.com/json/default.asp">http://www.w3schools.com/json/default.asp

Block the button for a while after pressing it

Q:
This is to be used for example when actuating a garage door and the magnetic contact is down. How can the user be sure that he pressed the button if the feedback is connected to this switch placed at end of run of the door? Does the functionality exist? What does it means "holding time"?

A:
You can use item property Enable with script, when pressing to Item Enable = 0 and command Send. 
When receive Feedback then Enable = 1;

Or you use full screen Popup Show when pressing  to Item and when receive Feedback then Hide full screen Popup


Holding Time is item property, is time interval of start event pressing to activate event Hold.

screensaver

Q:
In the last mailing from Iridiummobile, when version 2.0.7 was released, there was an item about screensavers.
See image below.
How can I create an analog clock as an screensaver?

A:
You can read how create analog clock an create this
http://www.iridiummobile.net/blog/how-to-create-analogue-clocks-in-iridium-gui-editor">http://www.iridiummobile.net/blog/how-to-create-analogue-clocks-in-iridium-gui-editor

or you can use ready project in gallery iRidium Samples / Screensavers

screensaver.jpg

Create project tokens

Q:
Is it possible to create project tokens with Javascript?
I couldn't find any information about it.

A:
if project token TokenName, not created in project, then script command

IR.SetVariable("Global.TokenName", Value) - will create this token

Selected Item info

Q:
I don't know if it's already possible but I couldn't found it.
What I would like to see is that when I press on an item that the program knows what item is pressed.

I would like to use something like this:

IR.AddListener(IR.EVENT_ITEM_PRESS,IR.GetItem("Page 1").GetItem("Item 1"),function(this)
{  
  IR.Log(this.Text);
});
I know I could use: 'IR.GetItem("Page 1").GetItem("Item 1").Text'

But it would increase the programming speed and flexibility of the program if you ask me.
I think it would be nice if the program automatically knows whatis happening and we're able to use that during programming.

A:
thank you for your idea! I have transferred it to iRidium programmers.  At the moment for increasing the speed of script writing you can use this: 

var Item = IR.GetItem("Page 1").GetItem("Item 1"); 

IR.AddListener(IR.EVENT_ITEM_PRESS, Item ,function()  
{    
  IR.Log(Item.Text);  
});

Great guide to object oriented javascript. ))- advanced users

Hi,

This is for the advanced scripters.  Watch the video on this site.
thanks,

Roger


Object Playground: The Definitive Guide to Object-Oriented JavaScript

An excellent (and definitive), illustrated guide to JavaScript objects.

How do I call Execute from JS

Q:
 How do I call Execute from JS?!

A:
you can use: http://wiki2.iridiummobile.net/index.php/Systems_API#IR.Execute">http://wiki2.iridiummobile.net/index.php/Systems_API#IR.Execute

Popup page sending states

Q:
for one project I would like to change the state of a button when a popup is shown
is it possible to integrate this and so,
 
what are the type and feedback relations I have to use?

A:
You can use the following listener events to determine whether a page or popup is shown or not.  just change it for your specific popup and add the code to adjust the global variable in the function of the listener.

  // triggered when popup 1 is shown
  IR.AddListener(IR.EVENT_ITEM_SHOW, IR.GetPopup("Popup 1"), function(){
  IR.Log("SHOWING POPUP 1");
  });

  //triggered when popup 1 is hidden
  IR.AddListener(IR.EVENT_ITEM_HIDE, IR.GetPopup("Popup 1"), function(){
  IR.Log("HIDING POPUP 1");
  });

Project Tokens Scripting

rocfusion:

Hi,

When you are using project tokens in your scripts. Be careful to watch for invalid tokens.

To account for this you could use something like this, it would be placed in the init part of your script.

if(IR.GetVariable("Global.MyToken")==undefined || IR.GetVariable("Global.MyToken")==NaN || IR.GetVariable("Global.MyToken")==null) { IR.SetVariable("Global.MyToken",0) }      

Here if MyToken is not valid it will reset to the value of 0.


Thanks,


Roger

Cant fill the value (info)

Q:
The line:

IR.GetItem("Popup").GetItem("Item 1").Value = 50;

Doesn't work in Javascript, If I use Text in stead of Value it works fine. 

A:
Please change  item property "Feedback" = channel.