Welcome to Programming LiveCode Q&A, where you can ask questions and receive answers from other members of the community.

Please, ask questions about the book only. If possible, mention section or page number. Don't ask for opinions, ask clear and direct questions only.

Go to main site

Quick Links

Frequently Asked Questions

Errata (1st print)

function Spaces doesn't work

+1 vote
p 225, bottom:

as it is, the function doesn't work, because the repeat argument tries to divide a number by a string

it could be corrected by:

put "                                          " into mySpace

put the length of mySpace into mySpaceLength

repeat max(1,trunc(theAmount/mySpaceLength) + 1) -- I would use "trunc" rather than "round" here

or

repeat max(1,(theAmount div mySpaceLength) + 1)

PS: according to my test, this function is about 20 times faster than the second one, top of p. 226
asked Jun 12, 2013 by jhausser (730 points)
retagged Aug 5, 2013 by mark

2 Answers

0 votes
 
Best answer

This has been corrected in the next print.

What exactly is the first and what is the second function? Which one is actually faster?

 

Edit:

The complete, correct script is

function spaces theAmount

  put "                                      " into mySpace

  repeat max(1,round(theAmount/length(mySpace))+1)

    put mySpace after myManySpaces

  end repeat

  return char 1 to theAmount of myManySpaces

end spaces

answered Jul 17, 2013 by mark (3,090 points)
selected Jul 30, 2013 by mark
Sorry, I was unclear. I mean: the function "spaces" (after correction) is about 20 times faster than the equivalent for spaces of the function "tabs", p. 226.
But that's ok, right? In the book, it is stated that the tabs function doesn't have to be as complicated as the spaces function, because the number of tabs you'd want to get returned is usually smaller. If you have a need for a very fast tabs function, you can adjust it to resemble the spaces function.
Yes, it is quite OK. Whith this comment I mostly wanted to emphasize the fact that a seemingly more complicated script can be faster than a simple and straightforward one... what's not always obvious for beginners.
+1 vote

I have found a better way to do this.

function spaces theAmount

  set the itemDel to space

  put space into item theAmount of myData

  return myData

end spaces

answered Nov 20, 2013 by mark (3,090 points)
...