Page 1 of 1

Complete beginner question

Posted: Mon Aug 17, 2015 4:45 pm
by dunbarx
Make a field and a button.

Put this into the button script:

Code: Select all

on mouseUp
put "111 222 333 444" into fld 1
wait 30
   put "xxx" into word -2 to -1 of fld 1
end mouseUp
Very nice.

Now this in the button script:

Code: Select all

on mouseUp
put "111 222 333 444" into fld 1
wait 30
   put "xxx" into word -1 to -2 of fld 1
end mouseUp
My question is this: Just don't? Or is this a feature? Even if the engine was trying to "insinuate" a new word between the last and second last words (to try to do its best with a mangled syntax not its fault, which might be interesting), it should not prepend to the last word.

Just don't?

Craig Newman

Re: Complete beginner question

Posted: Mon Aug 17, 2015 5:30 pm
by FourthWorld
This seems somewhat consistent with the way chunk ranges work in xTalks, in that left-to-right expressions are treated as a range and right-to-left expressions are treated as an insertion point.

For example, if you select word 3 to 4 manually the selectedChunk will be "char 9 to 18 of field 1", but if you insert the cursor into an empty selection the chunk is something like "char 10 to 9 of field 1".

Whether the engine should modify what's being inserted to add another space is deeper than I'd venture; happy to leave that to Mark Waddingham.

What would HyperCard do?

Although HC didn't support negative integers in chunk ranges, the same principle plays out here with positive integers, e.g. "word 4 to 3 of field 1". I'd wager the mother tongue did the same thing, though it would be interesting to know if it doesn't, and even more interesting to know what that different result is.

What were you working on when you stumbled across this?

Re: Complete beginner question

Posted: Mon Aug 17, 2015 6:36 pm
by dunbarx
Richard.
Although HC didn't support negative integers in chunk ranges,
Oh yeah? (I wonder how many others here will be interested in this). So in HC starting with :

Code: Select all

on mouseUp
   put "111 222 333 444" into fld 1
   wait 30
   put "xxx" into word -1 of fld 1
end mouseUp
gives: "xxx"

Code: Select all

 put "xxx" into word -2 of fld 1
gives "111 222 333 xxx"

Code: Select all

 put "xxx" into word -3 of fld 1
gives "111 222 xxx 444" --Works!

Code: Select all

 put "xxx" into word -4 of fld 1
gives "111 222 333 xxx" --Same as "-2"!

Now then:

Code: Select all

 put "xxx" into word -4 to -2 of fld 1
gives "111 222 xxx 444" --!

Other combinations of negative values give odd results, never an error, though. I do not want to even try to figure out what HC might be doing with those two values.

I saw this with a typo in LC. I reversed the two values and got a weird result.

Craig

Re: Complete beginner question

Posted: Mon Aug 17, 2015 7:04 pm
by FourthWorld
Thanks - I'd never seen any examples of negative values in HyperTalk, so I had assumed that wasn't supported. Useful to know.

I suppose you could file a bug report on this. If there's a good reason for why the behavior should differ from HyperTalk's they'll offer it there.

Was there a problem you're working on that we might be able to help with, or just exploring the edges of the engine?

Re: Complete beginner question

Posted: Mon Aug 17, 2015 7:14 pm
by dunbarx
But is it a bug? There is no formal syntax for what I did.

Edges? I don't need no stinking edges.

Thanks for asking, though.

Craig

Re: Complete beginner question

Posted: Mon Aug 17, 2015 7:44 pm
by FourthWorld
Well, it differs from the mother tongue, and in an unexpected way. If they don't feel it's a bug at least they'll provide an explanation, which seems useful in itself.