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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom 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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.