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

Fallout Shelter pulls in ten times its u...
When the Fallout TV series was announced I, like I assume many others, assumed it was going to be an utter pile of garbage. Well, as we now know that couldn't be further from the truth. It was a smash hit, and this success has of course given the... | Read more »
Recruit two powerful-sounding students t...
I am a fan of anime, and I hear about a lot that comes through, but one that escaped my attention until now is A Certain Scientific Railgun T, and that name is very enticing. If it's new to you too, then players of Blue Archive can get a hands-on... | Read more »
Top Hat Studios unveils a new gameplay t...
There are a lot of big games coming that you might be excited about, but one of those I am most interested in is Athenian Rhapsody because it looks delightfully silly. The developers behind this project, the rather fancy-sounding Top Hat Studios,... | Read more »
Bound through time on the hunt for sneak...
Have you ever sat down and wondered what would happen if Dr Who and Sherlock Holmes went on an adventure? Well, besides probably being the best mash-up of English fiction, you'd get the Hidden Through Time series, and now Rogueside has announced... | Read more »
The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
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 »

Price Scanner via MacPrices.net

Sunday Sale: Take $150 off every 15-inch M3 M...
Amazon is now offering a $150 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 15″ M3 MacBook... Read more
Apple’s 24-inch M3 iMacs are on sale for $150...
Amazon is offering a $150 discount on Apple’s new M3-powered 24″ iMacs. Prices start at $1149 for models with 8GB of RAM and 256GB of storage: – 24″ M3 iMac/8-core GPU/8GB/256GB: $1149.99, $150 off... Read more
Verizon has Apple AirPods on sale this weeken...
Verizon has Apple AirPods on sale for up to 31% off MSRP on their online store this weekend. Their prices are the lowest price available for AirPods from any Apple retailer. Verizon service is not... Read more
Apple has 15-inch M2 MacBook Airs available s...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs available starting at $1019 and ranging up to $300 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at Apple.... Read more
May 2024 Apple Education discounts on MacBook...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $300 off the purchase of a new MacBook... Read more
Clearance 16-inch M2 Pro MacBook Pros in stoc...
Apple has clearance 16″ M2 Pro MacBook Pros available in their Certified Refurbished store starting at $2049 and ranging up to $450 off original MSRP. Each model features a new outer case, shipping... Read more
Save $300 at Apple on 14-inch M3 MacBook Pros...
Apple has 14″ M3 MacBook Pros with 16GB of RAM, Certified Refurbished, available for $270-$300 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year warranty is... Read more
Apple continues to offer 14-inch M3 MacBook P...
Apple has 14″ M3 MacBook Pros, Certified Refurbished, available starting at only $1359 and ranging up to $270 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year... Read more
Apple AirPods Pro with USB-C return to all-ti...
Amazon has Apple’s AirPods Pro with USB-C in stock and on sale for $179.99 including free shipping. Their price is $70 (28%) off MSRP, and it’s currently the lowest price available for new AirPods... Read more
Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more

Jobs Board

Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
*Apple* App Developer - Datrose (United Stat...
…year experiencein programming and have computer knowledge with SWIFT. Job Responsibilites: Apple App Developer is expected to support essential tasks for the RxASL Read more
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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.