Trying to learn userprops!

Here's where to discuss using Stéphane Leys' very well done alternative runtime editor. If you're a control freak at runtime you have to check this out!

Trying to learn userprops!

Postby drpitcairn » Mon May 18, 2009 7:38 pm

OK. I defined a userprop for my card, called gradeprocessor. Then I used this script to put data into it.
Code: Select all
on mouseup
set the gradeprocessor of this cd to empty
repeat with x = 6 to 10
if cd fld x is empty then next repeat
put cd fld x & return after tholder
end repeat
set the gradeprocessor of this cd to tholder
cleanup
end mouseup


I ran the first part (without cleanup) and it put the data into gradeprocessor though I noticed that the data was not visible until I clicked back and forth on the userprop first. I assumed it would be visible like in a field.
Anyway, there was a blank line in the list which I solved with the fields I used before by putting in this script as a subroutine:
Code: Select all
--• checks for empty lines containing only the return char.
on cleanup
repeat with b = 1 to the number of lines in the gradeprocessor
if line b of the gradeprocessor is empty
then
delete line b of the gradeprocessor
end if
end repeat
end cleanup

But then the script does not go, gets stuck on the line about repeating the lines.
So I went back into the starting cd fld 6 and put in the msg box "cd fld 6 contains return" and get "false". But my original script that puts data into cd fld 6 specifies putting a return in, like this:
Code: Select all
put replace(gremedyList,space & space,cr) into cd fld "list1"

So how could it not have returns in it? Like I am totally puzzled.

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

Re: Trying to learn userprops!

Postby S. Leys » Tue May 19, 2009 1:11 am

rpitcairn wrote:
Code: Select all
--• checks for empty lines containing only the return char.
on cleanup
repeat with b = 1 to the number of lines in the gradeprocessor
if line b of the gradeprocessor is empty
then
delete line b of the gradeprocessor
end if
end repeat
end cleanup

But then the script does not go, gets stuck on the line about repeating the lines.

When you post a script, copy it with cmd-shift-C, it will copy the indentation, it's much easier to read.
If gradeprocessor is a variable, you must do "the number of lines in gradeprocessor", "the" belongs to the syntax of properties. If gradeprocessor is a property, you must do "the gradeprocessor of SomeObject", properties belong to an object ("the something" is the syntax of a global property). But you can't put, delete ... etc the data in a userprop directly, you must first put the userprop into a variable an set the userprop to this variable after working on it.
There is an algorithmic error in your script. Imagine that line 5 and 6 are empty. when the index of the loop reaches 5, the empty line 5 will be deleted and thus line 6 will become line 5 and thus line 5 will still be empty. Then the index will be incremented to 6 and you'll miss the new empty line 5.
When you're deleting lines from a container, you must start from the bottom : repeat with i = num of lines of myVar down to 1.
Another thing is that, if the last char of the variable is a cr, it won't be counted as a line (ditto for items)
So I went back into the starting cd fld 6 and put in the msg box "cd fld 6 contains return" and get "false". But my original script that puts data into cd fld 6 specifies putting a return in, like this:
Code: Select all
put replace(gremedyList,space & space,cr) into cd fld "list1"

So how could it not have returns in it? Like I am totally puzzled.


I guess that gremedyList didn't contain space & space
Code: Select all
function stripEmptyLines x
    if x="" then return ""
    get x
    repeat while cr&cr is in it
        get replace(it,cr&cr,cr)
    end repeat
    repeat while char 1 of it=cr
        delete char 1 of it
    end repeat
    repeat while last char of it=cr
        delete last char of it
    end repeat
    return it
end stripEmptyLines


S.
User avatar
S. Leys
 
Posts: 628
Joined: Sun Jul 06, 2008 11:03 am

Re: Trying to learn userprops!

Postby S. Leys » Tue May 19, 2009 1:20 am

rpitcairn wrote:OK. I defined a userprop for my card, called gradeprocessor. Then I used this script to put data into it.
Code: Select all
on mouseup
set the gradeprocessor of this cd to empty
repeat with x = 6 to 10
if cd fld x is empty then next repeat
put cd fld x & return after tholder
end repeat
set the gradeprocessor of this cd to tholder
cleanup
end mouseup


I ran the first part (without cleanup) and it put the data into gradeprocessor though I noticed that the data was not visible until I clicked back and forth on the userprop first. I assumed it would be visible like in a field.


Here, when I set a userprop from a script and this userprop is selected in the userprop module, it is updated as soon as the script returns. But I worked on this module recently and improved it, so this might be a glitch in the current version of MPI.

S.
User avatar
S. Leys
 
Posts: 628
Joined: Sun Jul 06, 2008 11:03 am


Return to Using MPI

Who is online

Users browsing this forum: No registered users and 1 guest