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

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 »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »

Price Scanner via MacPrices.net

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
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more
Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more

Jobs Board

Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
IT Systems Engineer ( *Apple* Platforms) - S...
IT Systems Engineer ( Apple Platforms) at SpaceX Hawthorne, CA SpaceX was founded under the belief that a future where humanity is out exploring the stars is Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.