PDA

View Full Version : Function: Run It Once


playmenow
04-07-2006, 06:01 AM
Thanks Adam for this awesome function! (Source = AMS5 Examples forum)

What do you do when you want your application to perform a certain set of actions - but only one time ever? This function does just that. It keeps track of whether or not the actions have been called before and will return true if they have been and false if they have not.

Place this code into your Global Functions section. Make sure to replace the text "Your_Application_Name" with your own unique application name.


--[[ This function will be used as a way to carry out an event
the first time that the autorun is run. function ShowOnce(key)
Always test to see if the value has been saved before]]
local Saved = Application.LoadValue("Your_Application_Name", key);
-- If it has not been saved before
if Saved == "" then
-- Save the value
Application.SaveValue("Your_Application_Name", key, "TRUE");
-- Return false
return false;
else
-- This means that the value has been saved before
return true;
end
end



You can call this function and use the result from anywhere. In this example, I put the following script into the first page's OnShow event. This will hide an object if it is not the first time that the application has been run.


-- call this function every time that the application is run.
Show = ShowOnce("ValueName");
if Show then
-- hide the object because it has been shown once before Label.SetVisible("Label1", false);
end

goukilord10
08-14-2006, 11:40 AM
and where the data is saved when using Application.SaveValue ??
registry ?, HD ?

TJ_Tigger
08-14-2006, 11:44 AM
This data is stored in the registry in the following key.

HKEY_CURRENT_USER\Software\Indigo Rose\ACData.

HTH
Tigg