FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister   ProfileProfile    Log inLog in   RSS Feed

Saving data

 
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Windows
View previous topic :: View next topic  
Author Message
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Fri Mar 23, 2007 5:17 pm    Post subject: Saving data Reply with quote

I was wondering if it is possible to save some data, either on the mobile phone, or on the computer, and how to retrieve it back in. I was thinking of making a script which lets the user easaly make any button on the phone to perform a buttonpress on the computer. F.eks, one enter setup mode in the script on the phone, and then press f.eks, '1'. and then you can choose which buttons '1' will trigger on the phone, and then saves the configuration, and then every time from there that the user presses '1', the computer thinks it is f.eks ctrl+A that is being pressed.
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Fri Mar 23, 2007 5:29 pm    Post subject: Reply with quote

Here's how the iTunes script reads its settings (and state). This is in the beginning of the script (not inside a handler):

[code:1]
// FileSystemObject for use in this script
var fso = new ActiveXObject( "Scripting.FileSystemObject" );

// Settings (persisted in txt file)
var setting_artwork_newlayout = 0;
var setting_moremenu_item = 0;

// Read settings for this script
try {
var settingsFileStream = fso.OpenTextFile( settingsPath + "\\settings.txt", 1, false );
if( settingsFileStream == null ) {
// Write defaults
writeSettings();
settingsFileStream = fso.OpenTextFile( settingsPath + "\\settings.txt", 1, false );
}
while( true ) {
var propertyName = settingsFileStream.ReadLine();
var propertyValue = settingsFileStream.ReadLine();
if( propertyName == "setting_artwork_newlayout" ) {
setting_artwork_newlayout = parseInt( propertyValue );
} else if( propertyName == "setting_moremenu_item" ) {
setting_moremenu_item = parseInt( propertyValue );
}
}
} catch( e ) {
} finally {
if( settingsFileStream != null ) settingsFileStream.Close();
}
[/code:1]

And then, whenever a setting is changed in the script, this function is called:

[code:1]
function writeSettings()
{
try {
var settingsFileStream = fso.CreateTextFile( settingsPath + "\\settings.txt", true ); // overwrite
settingsFileStream.WriteLine( "setting_artwork_newlayout" );
settingsFileStream.WriteLine( setting_artwork_newlayout );
settingsFileStream.WriteLine( "setting_moremenu_item" );
settingsFileStream.WriteLine( setting_moremenu_item );
settingsFileStream.Close();
} catch( e ) {}
}
[/code:1]

Note the use of [b]settingsPath[/b]! This is a property set by the Clicker runtime. It points to a file system location (unique for this script) where it's suitable for you to write your settings file(s).

So, given the above, a code segment in your script might do this:

[code:1]
setting_artwork_newlayout = 2;
writeSettings();
[/code:1]

This would change the value of a setting and then persist it to file, so that when the script is later invoked, the value of setting_artwork_newlayout would still be 2 (assuming your script begins with the snippet indicated above).

I hope this helps.

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Thu Mar 29, 2007 1:11 pm    Post subject: Reply with quote

thanks alot:D

I have a small problem though. I want to read the data from the textfile without setting which variables that should be stored.

[code:1]

function readSettings()
{
// Read settings for this script
try {
var settingsFileStream = fso.OpenTextFile( settingsPath + "\\settings.txt", 1, false );
if( settingsFileStream == null ) {
// Write defaults
writeSettings();
settingsFileStream = fso.OpenTextFile( settingsPath + "\\settings.txt", 1, false );
}
while( true ) {
var propertyName = settingsFileStream.ReadLine();
var propertyValue = settingsFileStream.ReadLine();
eval(propertyName) = propertyValue;
showMessage("Success!");

}
} catch( e ) {
} finally {
if( settingsFileStream != null ) settingsFileStream.Close();
}
}[/code:1]

this is a little piece of the code from above, where the problem is:
[code:1] while( true ) {
var propertyName = settingsFileStream.ReadLine();
var propertyValue = settingsFileStream.ReadLine();
eval(propertyName) = propertyValue;
showMessage("Success!");

}[/code:1]

in my textfile, these are the two first lines:
[code:1]key1type
launch[/code:1]

It reads the data from the file without any problems, but when I am trying to set the variables, it just won't work. Actually, without the eval(propertyName) = propertyValue;, the Message shows up, but with it, it doesn't. So it seems that the eval funtion makes the script stop. Why is this?
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Thu Mar 29, 2007 1:53 pm    Post subject: Reply with quote

I wish I had the time to help you with your (general) jscript question. Unfortunately, I don't. :-(

Maybe someone else can help you. To me, it sounds like you need to research jscript a little better, and perhaps choose a different implementation strategy.

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cmatte
Newbie


Joined: 19 Aug 2007
Posts: 10

PostPosted: Sun Aug 19, 2007 1:03 am    Post subject: Reply with quote

I really need to know where these settings are stored because I completely locked my salling clicker software using the all-around script: as soon as it connects it continues telling me that iTunes connection can't be done...it's true, but even if I click OK maaaaany times the popup remains and refreshes continuously...
Please :cry:
Back to top
View user's profile Send private message MSN Messenger
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Sun Aug 19, 2007 4:14 pm    Post subject: Reply with quote

oh... a serious bug there... hmm... I'll work on a fix, I know what is causing it. just hang in there... in the meentime, you could check out this folder: "C:\Documents and Settings\Administrator\Programdata\Salling Software AB\Script Settings"

I am running a norwegian version of windows cp, which for some reason is partially english. I'll try to translate the path into english. it should be something like this:

"C:\Documents and Settings\Administrator(or the user who is logged in\Application data or program data\Salling Software AB\Script Settings"

once you have found that folder, you will see alot of folders with crazy naming, lots of digits and stuff. the all-around-script uses this folder: "7532d0ee-dc02-11db-8314-0800200c9a66"

hope this helps for now.
Back to top
View user's profile Send private message
salling
Site Admin


Joined: 27 Jul 2004
Posts: 7498
Location: Stockholm, Sweden

PostPosted: Sun Aug 19, 2007 4:46 pm    Post subject: Reply with quote

@ Runarius

%APPDATA% will bring Windows Explorer to the correct folder, regardless of OS version.

Best.
--
Jonas
Back to top
View user's profile Send private message Send e-mail Visit poster's website
cmatte
Newbie


Joined: 19 Aug 2007
Posts: 10

PostPosted: Sun Aug 19, 2007 5:16 pm    Post subject: Reply with quote

Solved, I've written it in the All-Around thread and forgot saying it here too, sorry!
Anyway, thanks!!
I'm "on board" now and playing with the script hehe :)
Back to top
View user's profile Send private message MSN Messenger
Runarius
Senior Member


Joined: 19 Nov 2006
Posts: 124

PostPosted: Sun Aug 19, 2007 6:53 pm    Post subject: Reply with quote

yeah, I saw your post and solution to your problem right after I posted it here;P

just wanted to tell people who are reading this post that the bug in the all-around-script should be fixed within a little while. starting on it right now.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Salling Software Forums Forum Index -> Scripting Salling Clicker for Windows All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group