Demo vs. registering a project sale.

Using Standalone Maker to build executables or delivering projects for use with the SuperCard Player? Discuss it here.

Demo vs. registering a project sale.

Postby drpitcairn » Sat Sep 24, 2011 8:14 am

I posted before about how to set up a demo for people to download before buying and got some very good answers about ways this could be done. I am trying one of them which is to have the project write an external text file that will record such things as the number of times it has been opened and perhaps the date it was first opened. The idea would be that the project would check this file and if the number of openings has been exceeded or the the expiration date has been passed, then the user would get a message offering to sell it to them — like with some much software.
So I have made it his far, able to write a file in the Preferences folder.
Here is my script (developing it as a button for now, will be in the open project script eventually):
Code: Select all
on mouseup
    --    trace
    get findfolder("preferencesFolder","userDomain")
    put it into tpath
    put "GAregistration.txt" after tpath
    --    close file tpath
    open file tpath
    read from file tpath until eof
    put it
    write "number"&","& date( ) to file tpath
    close file tpath
    beep
end mouseup

So I do get the proper return from the file. But I don't know where to go from here. I do understand I can use the number of openings by adding a number to it and writing again. But what about date? Is there a way to compare dates so that I can know, for example, that 30 days have passed since they first opened it?

Another questions is about the way I set it up. I understand that I can write to my preferences folder since I have administrator privileges, but what about some other user that downloads this? Can it still write to their user folder?

Thanks for any suggestions?

Richard
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Demo vs. registering a project sale.

Postby Scott » Sat Oct 01, 2011 8:19 am

There should be no problem creating a file in the users preferences folder… that is what it was designed for.

As for comparing dates, it is probably simplest to use the seconds function and compare the results. There are 2592000 seconds in 30 days.
User avatar
Scott
Site Admin
 
Posts: 1243
Joined: Sat Jul 05, 2008 1:37 pm
Location: Northern Sierra Nevada

Re: Demo vs. registering a project sale.

Postby drpitcairn » Sat Oct 01, 2011 10:35 am

Thanks for the hint. Will look into that function.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Demo vs. registering a project sale.

Postby drpitcairn » Mon Oct 03, 2011 5:02 pm

Still working on this as I have time. I read about seconds, looks to be a solution for my question about dates, but now I am puzzled by another aspect. I read that the file, after being opened, should be closed by the script. But I wanted to see if there was some way to deal with a file if it was left open by the script so I modified the code to like this:
Code: Select all
on mouseup
    --    trace
    get findfolder("preferencesFolder","userDomain")
    put it into tpath
    put "GAregistration.txt" after tpath
    open file tpath
    read from file tpath until eof
    put it
    write "number"&","& date( ) to file tpath
    -- close file tpath
    beep
end mouseup

and I thought it would then leave the file open since I made the "close file" command not active. But when I run it repeatedly, seems just fine.
So then I tried this:
Code: Select all
on mouseup
    --    trace
    get findfolder("preferencesFolder","userDomain")
    put it into tpath
    put "GAregistration.txt" after tpath
    open file tpath
    put the result
    read from file tpath until eof
    write "number"&","& date( ) to file tpath
    --close file tpath
    beep
end mouseup

I thought that result would be "File already open", but all I get is an empty message box. So obviously I am not doing it right.
Can anyone give me guidance?
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Demo vs. registering a project sale.

Postby Dan_Kelleher » Mon Oct 03, 2011 7:54 pm

Looking at the 2nd portion of code,

"open file tpath" should create a new empty if one does not exist. Does that happen?
If one does exist the file will just be opened, allowing it to be read or written to.
your next line "put the result" yields empty, you say. You expected "File already open".
I'd say the file was not open when you opened it. Therefore, the result is empty.

Insert another set of the two-line combo right after the first set;

open file tpath
put the result
wait 180
put "I'm waiting"
wait 180
open file tpath
put the result
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Demo vs. registering a project sale.

Postby drpitcairn » Tue Oct 04, 2011 8:46 am

I did as you suggested. I do see the "I'm waiting" and then the box become empty after the next 180, so result is empty. I ran it a couple of times. Where I am confused is that if I don't include the line for "close tpath" then doesn't the file stay open? Guess not as it acts like it is closed when I run the script again — even without the "close" line.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Demo vs. registering a project sale.

Postby Dan_Kelleher » Wed Oct 05, 2011 8:17 am

Richard wrote:
Where I am confused is that if I don't include the line for "close tpath" then doesn't the file stay open?

Actually it's "close file tpath" but you know that and I think your observations and ideas here are all correct and you've discovered a bug.

The following script which is identical to the one in the "code box" was written to allow easy monitoring of the bug (at least one bug, I'd say) in the script tracer. The use of a field in addition is also helpful sometimes to get a more persistent "hard copy" of (the) code behavior, but watching the script tracer is enough here.

The result function [ "the result" or "result()" ] is not providing us with sufficient info to modify files with confidence (easily).

To run this test,
put the code into a card button of a new project
create one real field on the card
change the hard drive name shown in bold (MainS120) to the name of your hard drive
change the user name shown in bold (danielkelleher) to the name of your user name
Open TextEdit create a new file, type a bit of text, save the file to the desktop with this exact name:
"myFileOpenInTextEdit.rtf" (check to be sure the name contains only one ".rtf" because TextEdit itself will/may add it. Then save the file (to the desktop) BUT LEAVE IT OPEN --think of yourself here as a user of your standalone working on this open text file.
Then click the btn to run the script, using the step button in the script tracer. See if you agree with the comments I've added to some of the lines of code.

The first part of the script deals with creating a new file and writing to it (perhaps I/we need to be specifying creation of a TEXT file ?)
The second part of the script deals with writing to a previously-existing text file that the imagined standalone user might be able to get her hands on and mess with.

Richard, I think you are doing very well with your standalone work and your care and thoughtfulness helps me and others.
Thanks,
-Dan

on mouseUp
trace
put "MainS120:Users:danielkelleher:Desktop:myFileToCreate" into tPath
--
put "some text to write" & cr into tText
put "" into tResult
--
write tText after file tPath
put result() into tResult --file not open -OK
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath --file is created -OK
put result() into tResult --"file not open" -OK
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath
put result() into tResult --eMPTY --> NOT OK-expected "File Already open"-NOT OK
put tResult & cr after cd fld 1
put "" into tResult
--
write tText after file tPath --Presumed written-Confirmed(File doubleClicked then closed via Red CloseButton)-OK
put result() into tResult --empty -OK
put tResult & cr after cd fld 1
put "" into tResult
--
close file tPath
put result() into tResult --Presumed Closed -- But see below that it's "File Open - Read Only" NOT OK ???
put tResult & cr after cd fld 1 --empty -OK
put "" into tResult
--
write tText after file tPath --Presumed NOT Written - Later confirmed -OK
put result() into tResult --"File is open - read only" --> NOT OK ---expected "File not open" - NOT OK
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath
put result() into tResult --empty - OK
put tResult & cr after cd fld 1
put "" into tResult
--
write tText after file tPath --Presumed written - Later confirmed - OK
put result() into tResult --empty - OK
put tResult & cr after cd fld 1
put "" into tResult
--
close file tPath
put result() into tResult --empty - OK
put tResult & cr after cd fld 1
put "" into tResult
--
--
put "MainS120:Users:danielkelleher:Desktop:myFileOpenInTextEdit.rtf" into tPath --This File is open in TextEdit
--
write tText after file tPath --Presumed not written-later confirmed-OK
put result() into tResult --"File is open - read only" - OK I'd say
put tResult & cr after cd fld 1 --NOTE THAT ONE WOULD NOT NORMALLY EVEN TRY TO WRITE BEFORE OPENING
put "" into tResult
--
open file tPath
put result() into tResult --empty-- NOT NOT OK -- TextEdit's got a user working on it!
put tResult & cr after cd fld 1 --NOTE THAT here we start doing things the normal way - Open THEN Write
put "" into tResult
--
write tText after file tPath --Presumed written - Later found to be FALSE ASSUMPTION
put result() into tResult --empty - NOT NOT OK -- I THINK I"ve Written but HAVE NOT. NOT OK
put tResult & cr after cd fld 1 --THE OS OR TextEdit or SC has protected the file from me but I don't know it-NOT OK
put "" into tResult
--
close file tPath
put result() into tResult --empty-OK
put tResult & cr after cd fld 1
put "" into tResult
--
end mouseUp

Code: Select all
on mouseUp
trace
put "MainS120:Users:danielkelleher:Desktop:myFileToCreate" into tPath
--
put "some text to write" & cr into tText
put "" into tResult
--
write tText after file tPath
put result() into tResult       --file not open -OK
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath                 --file is created -OK
put result() into tResult       --"file not open" -OK
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath
put result() into tResult       --eMPTY --> NOT OK-expected "File Already open"-NOT OK
put tResult & cr after cd fld 1
put "" into tResult
--
write tText after file tPath    --Presumed written-Confirmed(File doubleClicked then closed via Red CloseButton)-OK
put result() into tResult       --empty -OK
put tResult & cr after cd fld 1
put "" into tResult
--
close file tPath
put result() into tResult       --Presumed Closed -- But see below that it's "File Open - Read Only" NOT OK ???
put tResult & cr after cd fld 1 --empty -OK
put "" into tResult
--
write tText after file tPath    --Presumed NOT Written - Later confirmed -OK
put result() into tResult       --"File is open - read only" --> NOT OK ---expected "File not open" - NOT OK
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath
put result() into tResult       --empty - OK
put tResult & cr after cd fld 1
put "" into tResult
--
write tText after file tPath    --Presumed written - Later confirmed - OK
put result() into tResult       --empty - OK
put tResult & cr after cd fld 1
put "" into tResult
--
close file tPath
put result() into tResult       --empty - OK     
put tResult & cr after cd fld 1
put "" into tResult
--
--
put "MainS120:Users:danielkelleher:Desktop:myFileOpenInTextEdit.rtf" into tPath --This File is open in TextEdit
--
write tText after file tPath    --Presumed not written-later confirmed-OK
put result() into tResult       --"File is open - read only" - OK I'd say
put tResult & cr after cd fld 1 --NOTE THAT ONE WOULD NOT NORMALLY EVEN TRY TO WRITE BEFORE OPENING
put "" into tResult
--
open file tPath
put result() into tResult       --empty-- NOT NOT OK -- TextEdit's got a user working on it!
put tResult & cr after cd fld 1 --NOTE THAT here we start doing things the normal way - Open THEN Write
put "" into tResult
--
write tText after file tPath    --Presumed written - Later found to be FALSE ASSUMPTION
put result() into tResult       --empty - NOT NOT OK -- I THINK I"ve Written but HAVE NOT. NOT OK
put tResult & cr after cd fld 1 --THE OS OR TextEdit or SC has protected the file from me but I don't know it-NOT OK
put "" into tResult
--
close file tPath
put result() into tResult      --empty-OK
put tResult & cr after cd fld 1
put "" into tResult
--
end mouseUp
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Demo vs. registering a project sale.

Postby drpitcairn » Wed Oct 05, 2011 3:08 pm

Will give it a try.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Demo vs. registering a project sale.

Postby drpitcairn » Sat Oct 08, 2011 5:00 pm

I finally got some time to try it. Hope I did it right. Followed instructions except when I made the assumption (though you didn't say to) to change the file name in script to read:
Code: Select all
put "Macbook Pro (2):Users:drpitcairn:Desktop:myFileOpenInTextEdit.rtf" into tPath


So running it like that, many errors. Here is the script with error indicated:
_____________________________________
on mouseUp
trace
put "Macbook Pro (2):Users:drpitcairn:Desktop:myFileOpenInTextEdit.rtf" into tPath
--
put "some text to write" & cr into tText
put "" into tResult
--
write tText after file tPath
put result() into tResult       --file not open -OK
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath                 --file is created -OK
put result() into tResult       --"file not open" -OK
put tResult & cr after cd fld 1 (was empty)
put "" into tResult
--
open file tPath
put result() into tResult       --eMPTY --> NOT OK-expected "File Already open"-NOT OK (was empty)
put tResult & cr after cd fld 1
put "" into tResult
--
write tText after file tPath    --Presumed written-Confirmed(File doubleClicked then closed via Red CloseButton)-OK
put result() into tResult       --empty -OK
put tResult & cr after cd fld 1
put "" into tResult
--
close file tPath
put result() into tResult       --Presumed Closed -- But see below that it's "File Open - Read Only" NOT OK ???
put tResult & cr after cd fld 1 --empty -OK
put "" into tResult
--
write tText after file tPath    --Presumed NOT Written - Later confirmed -OK
put result() into tResult       --"File is open - read only" --> NOT OK ---expected "File not open" - NOT OK (was empty)
put tResult & cr after cd fld 1
put "" into tResult
--
open file tPath
put result() into tResult       --empty - OK
put tResult & cr after cd fld 1
put "" into tResult
--
write tText after file tPath    --Presumed written - Later confirmed - OK
put result() into tResult       --empty - OK
put tResult & cr after cd fld 1
put "" into tResult
--
close file tPath
put result() into tResult       --empty - OK     
put tResult & cr after cd fld 1
put "" into tResult
--
--
put "MainS120:Users:danielkelleher:Desktop:myFileOpenInTextEdit.rtf" into tPath --This File is open in TextEdit
--
write tText after file tPath    --Presumed not written-later confirmed-OK
put result() into tResult       --"File is open - read only" - OK I'd say (said file not open)
put tResult & cr after cd fld 1 --NOTE THAT ONE WOULD NOT NORMALLY EVEN TRY TO WRITE BEFORE OPENING
put "" into tResult
--
open file tPath
put result() into tResult       --empty-- NOT NOT OK -- TextEdit's got a user working on it! (was empty)
put tResult & cr after cd fld 1 --NOTE THAT here we start doing things the normal way - Open THEN Write
put "" into tResult
--
write tText after file tPath    --Presumed written - Later found to be FALSE ASSUMPTION
put result() into tResult       --empty - NOT NOT OK -- I THINK I"ve Written but HAVE NOT. NOT OK (was empty)
put tResult & cr after cd fld 1 --THE OS OR TextEdit or SC has protected the file from me but I don't know it-NOT OK
put "" into tResult
--
close file tPath
put result() into tResult      --empty-OK (error window appears)
put tResult & cr after cd fld 1
put "" into tResult
--
end mouseUp
_____________________________________

Could not finish entire script because of error window. Tried twice.
Here is a picture of that window:
error in script.png
error window at end of script
error in script.png (23.25 KiB) Viewed 5830 times
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Demo vs. registering a project sale.

Postby Dan_Kelleher » Sun Oct 09, 2011 6:36 pm

Hi Richard,
I don't know why you got that error window (the line looks ok) but, overall, I think it's clear that you have found some problems with the result function and you should file a bug report.
-Dan
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Demo vs. registering a project sale.

Postby drpitcairn » Sun Oct 09, 2011 7:19 pm

Yeah, I got the error window twice. I couldn't see why either. In filing a bug report would I just refer to this message string? Or should I copy it all and paste into that place?
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona

Re: Demo vs. registering a project sale.

Postby Dan_Kelleher » Mon Oct 10, 2011 2:36 pm

Hi Richard,
Do what you think is best but the following shorter-form seems to me to focus on the issues at hand in a clearer manner; to address the possibility that the result function is not returning everything we think it should.
(I cleaned up the script a bit)
-Dan

on mouseUp
trace
--BUG1
--
put "MainS120:Users:danielkelleher:Desktop:myFileToCreate" into tPath
--
put "some text to write" & cr into tText
put "" into tResult
--
open file tPath --file is created -OK
put result() into tResult --"file not open" -OK ?
put "" into tResult
--
open file tPath
put result() into tResult --empty --> NOT OK-expected "File Already open"-NOT OK BUG1
put "" into tResult
--
write tText after file tPath --Presumed written-Confirmed-OK
put result() into tResult --empty -OK
put "" into tResult
--
--BUG2
--
put "MainS120:Users:danielkelleher:Desktop:myFileOpenInTextEdit.rtf" into tPath --This File is open in TextEdit
--
open file tPath
put result() into tResult --empty-- NOT NOT OK -- TextEdit's got a user working on it! BUG 2
put "" into tResult
--
write tText after file tPath --Presumed written - Later found to be FALSE ASSUMPTION
put result() into tResult --empty - NOT NOT OK -- I THINK I"ve Written but HAVE NOT- NOT OK
put "" into tResult
--
--close file tPath
put result() into tResult --empty-OK
put "" into tResult
--
end mouseUp
Daniel.Kelleher@umassmed.edu
SC4.7.3 OSX 10.7.2 Mac Pro
User avatar
Dan_Kelleher
 
Posts: 438
Joined: Sun Jul 06, 2008 2:45 pm
Location: Worcester (wouster as in would) Massachusetts USA

Re: Demo vs. registering a project sale.

Postby drpitcairn » Thu Oct 20, 2011 6:38 pm

Dan,
I ran this script. There were no messages at all coming up. Nada. I think I did it right, had the rtf file open on the desktop, built the project with a field on it, put the script into the button, put my details into the file path — but I couldn't see anything happening in the trace. No messages.
User avatar
drpitcairn
 
Posts: 1023
Joined: Thu Apr 02, 2009 9:39 am
Location: Sedona, Arizona


Return to Building Standalones

Who is online

Users browsing this forum: No registered users and 1 guest