TweetFollow Us on Twitter

September 94 - Newton Q & A: Ask the Llama

Newton Q & A: Ask the Llama

Newton Developer Technical Support

Q I'm having trouble with the protoRoll. I have a protoApp with a protoRoll at the bottom with a couple of items in it. (Note that I'm not using the protoRollBrowser proto.) It compiles OK, but when I download to the Newton, nothing shows up. In fact, when I use the inspector to look at the view hierarchy, the protoRoll doesn't show up at all. The other views are fine. What am I doing wrong?

A The protoRoll doesn't show up because of the setting of the viewFlags of the ROM prototype: the vApplication and vClipping flags are set, but not the vVisible flag. If the protoRoll were the base template of your application, the vApplication flag would be sufficient to make it visible.

In your case, the protoRoll is a child of your base application template. Since it isn't visible (vVisible isn't set), the system doesn't create a runtime view frame for the child. You could get the system to create the runtime view by declaring the protoRoll to be the base template, but this still wouldn't show the protoRoll.

To make the protoRoll visible, add a viewFlags slot to the protoRoll and check the vVisible flag. You may or may not want to uncheck the vApplication flag. If you uncheck it, the system will no longer send scroll and overview messages (viewScrollUpScript, viewScrollDownScript, viewOverviewScript) to the protoRoll, so it will appear to be broken. But you can support these messages in your base application view and just pass them on to the protoRoll as needed. If you leave the vApplication flag checked, protoRoll will get the scroll events.

Q My print format never seems to get called, ever. I don't get a printNextPageScript or even a viewSetupFormScript. I'm not using ROM_coverPageFormat because I don't ever want to print a cover page. How can I get this to work?

A The answer to your problem is in your question. A print (or fax) format must proto to ROM_coverPageFormat; it's not optional (as the manual implies). It may help to know that ROM_coverPageFormat is really misnamed. The generation of a cover page is controlled by a slot in your format. The proto should be called something like ROM_allThePrintingAndFaxingBehaviorProto, but that would be verbose :-)

Q I would like to add a [button|view|Llama ] to the [Notepad|Calendar|Cardfile|etc. ]. How can I do that safely?

A This is a simple one: you can't. If you add any element to a built-in application, you take the chance that your application will break in future releases of MessagePad. Also note that adding llamas to MessagePad will theoretically cause a multidimensional implosion. ("Don't cross the llamas, er . . . beams." -- LlamaBusters)

Q I've noticed some peculiar behavior in the Compile function and am wondering if it might be a bug. The problem is with special characters and string objects. When Compile is passed a string object containing special characters rather than a literal string with Unicode codes, the result is incorrect. This example works as expected:

x:= Compile("{msg: \"A string with special character \u00A5\u\"}";
y:= :x();
--> y is {msg: "A string with special character ¥"} This example doesn't work as expected:
a:= "A string with special character \u00A5\u";
x:= Compile(a);
y:= :x();
--> y is {msg: "A string with special character *"} where * is some character other than the expected "¥".

Can you explain what's going on here?

A The problem is that you're using illegal NewtonScript syntax in the second example. If you used the inspector instead of Compile for this example, it would be like typing

A string with special character \u00A5\u

and then hitting Enter. This would result in a syntax error from NewtonScript. What you probably want is the equivalent of typing

"A string with special character \u00A5\u"

into the inspector. This is done with the following call to Compile:

x := Compile("\"A string with special character \\u00A5\\u\"");
call x with ();
--> #4415F49 "A string with special character ¥"

Note that the escape characters (\) for the Unicode string are themselves escaped. If you don't do this, you'll be putting the actual Unicode characters into the string being compiled, which is probably not what you want. Although your first example worked, you could easily get a case where not escaping the escape characters could bite you.

Q In the communications input spec below, why does the call to UpdateStatus fail? UpdateStatus is a method in my base view, and the whole endpoint is in my base view, so why can't the input spec find the method?

GetMessage: {
    inputForm: 'string,
    endCharacter: unicodeCR,
    InputScript: func(endpoint, data)
    begin
        :UpdateStatus(data);
        endpoint:SetInputSpec(GetMessage);
    end;
}

A The call to UpdateStatus fails because it's a message send that uses full inheritance to find the method. That means the system will look in the current context (that is, self), then check the proto chain, and then check the parent chain. However, the current context is not what you think it is. In an input spec, the current context is the frame that defines the input spec. In this case, it's the GetMessage frame you define.

Since the GetMessage frame has no proto or parent pointer, the message send fails. There's a second problem waiting to happen: the call to SetInputSpec will also fail, because the symbol GetMessage isn't valid in this context.

The solution is to get a reference to your base view (or another view that contains or inherits the UpdateStatus message). The usual way to do this is to add an _parent slot to your endpoint at run time during initialization. Now your InputScript can use endpoint._parent to find the base view, as follows:

InputScript: func(endpoint, data)
begin
    endpoint:UpdateStatus(data);
    endpoint:SetInputSpec(endpoint.GetMessage);
end;

If you really want to use a simple message send (for example, :UpdateStatus), you could add an _parent slot to the input spec. This may be useful in situations where you have several input scripts that rely on a dynamic inheritance mechanism. That is, you change what the _parent slot of the input spec points to on the fly.

Q Did you know that "gullible" is not in the Newton dictionary?

A It is now.

Q I have a large amount of static data in my application. I'd like to use Project Data to edit this data, but it won't fit. What can I do?

A You must have an old version of the Newton Toolkit. As of version 1.0.1, the 32K limit is gone. You could use another text editor to edit the Project Data file. You could also use the Load command to load another NewtonScript source file.

As an example, assume you had a file called MyData.f in the same directory as your project and that this file contained the script that defined your constant data structures. You could use the Load command like this:

// This line appears in your Project Data file.
// Load in the data file and use the HOME compile-time variable
// to get the path to the project folder.
Load(HOME & "MyData.f");

Q How can I figure out how much space my package and data will take on a card? I really want my application to fit on a 1-meg card.

A The short answer is, you can't. The long answer is, load your packages and soups after completely erasing the card. To completely erase the card, open up preferences and then insert the card. Before the card is loaded, you'll get a chance to erase it.

Look at the difference in the free space on the card. Use the value in the card dialog. The value in the remove-package picker is the uncompressed size. You must erase the card before you check the free space difference.

Q I have an input spec that receives data and places it into a queue. When I get data, I set a flag in my base view (DataInQ) that indicates data is available. I know the data is getting sent, but my input specs never seem to get called. What's going on?

A The chances are that your base view has some code like this:

myBase.WaitForData := func()
    while Not DataInQ do nil;

You may have more statements in the loop, and you may be using repeat instead of while, but you probably have a loop that waits for the DataInQ flag to be set. The problem is that you're not giving control back to the NewtonScript thread so that it can process the pending InputScript call (from your input spec).

If you really need to wait for data, you can use either an idle script or a repeating delayed action. The idle script will be significantly easier to implement. You should make the delay on your idle script long enough to give time to the Newton. Also note that the Newton is a battery-powered device, and excessive use of this kind of programming tends to drain the users -- I mean, batteries.

Q I have an array of text elements called MyFirstArray in my Project Data file. I want to set the text of a clParagraphView that I open to an item in this array. The clParagraphView has a slot (strRef) that references MyFirstArray[0]. The first element appears as the clParagraph's view. There are four buttons on the base view, and depending on which button is tapped I want a different element of this array to be the clParagraph's text. When I try replacing MyFirstArray[0] in strRef during the viewSetupFormScript, I get as text "MyFirstArray[1]", not the text this represents. Here's the code in SetupFormScript in the clParagraph:

SetValue(self, 'strRef, "MyFirstArray["&tempslot&"]");

tempslot is a slot in the base view where I store a value depending on which button is tapped. What's the problem?

A The basic answer is that your SetValue statement is incorrect. This statement sets strRef to the string "MyFirstArray[" concatenated with the string representation of tempslot concatenated with "]". What you really want is the string that's in MyFirstArray at the position defined by tempslot; that statement would be

SetValue(self, 'strRef, MyFirstArray[tempslot]);

But there are better ways to do this. Which method you use depends on when you set the text of the clParagraphView. If you set up things at open time, use the viewSetupFormScript, but just assign directly to the text slot:

 clParagraphView.viewSetupFormScript := func()
    text := MyFirstArray[tempslot];

Remember that SetValue will also dirty the view and call RefreshViews. This isn't something you want to happen when you Open a view.

The other case is that the clParagraphView is already open. In this case, you can use a SetValue statement to set the text slot directly, instead of setting a strRef slot.

One other note: If the user can edit the strings you place in a clParagraphView, you must Clone the string. Otherwise you can get a "tried to modify read only object" error.

Q How long does it take to train a llama to be a competent NewtonScript programmer?

A About four weeks, but the hooves get in the way of really fast coding.

The llama is the unofficial mascot of the Developer Technical Support group in Apple's Personal Interactive Electronics (PIE) division. Send your Newton-related questions to NewtonMail DRLLAMA or AppleLink DR.LLAMA. The first time we use a question from you, we'll send you a T-shirt. *

Thanks to our PIE Partners for the questions used in this column, and to jXopher, Todd Courtois, Bob Ebert, Mike Engber, Kent Sandvik, Jim Schram, Maurice Sharp, and Scott ("Zz") Zimmerman for the answers. *

Have more questions? Need more answers? Take a look at PIE Developer Info on AppleLink. *

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »

Price Scanner via MacPrices.net

Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.