Array

Want to move your code and projects to LiveCode but don't know where to start?

Moderators: FourthWorld, heatherlaine, Klaus, robinmiller

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Tue Nov 13, 2012 7:37 pm

This :@ ?
Attachments
Explains from Mark.zip
Hello
(873 Bytes) Downloaded 480 times

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Array

Post by Mark » Tue Nov 13, 2012 8:26 pm

Hi,

I had a look at your stack. You did everything right and the stack works exactly as it should. I only found one little mistake in my script. The button that calculates the days should have this script:

Code: Select all

on mouseUp
   set the itemDel to tab
   repeat with x =1 to number of lines of fld "List"
      put item 2 of line x of fld "List" into myDate
      convert myDate to seconds
      put round((myDate - the seconds)/86400) into myDays
      put myDays && "days left" into item 3 of line x of fld "List"
   end repeat
end mouseUp
I have changed

Code: Select all

put round((the seconds - myDate)/86400) into myDays
into

Code: Select all

put round((myDate - the seconds)/86400) into myDays
You already know the format for the date. You can see this by typing

Code: Select all

put the short date
in the message box. If this doesn't work for you, then tell me what you are entering in the date field exactly.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Tue Nov 13, 2012 9:01 pm

Thank you really much but you told me this things dont work 100% and I need 100% work :@

And I want this thing to be in object with lines and rows. So I want after I put the date into the field (for example im in card "Spoons" right now) and I press on the calculator it will put

the name of the card "Spoons" into the left row, the date of the card into the mid row and the days left into the right row. and all this I want to be on the first line. Which means, if I do the same thing from another card, it will go 2 secound line. How can I do that :@ ? and how can I make this code for all the cards i want it to be in ?

Thanks!

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Tue Nov 13, 2012 10:09 pm

And now when Im doing you'r code It shows me 3 days left when I write 11/15 for date or when im doing 11/14 it shows me there is 0 days left... Why is that ?

(It wasn't like that before few hours and I touched nothing)

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Array

Post by Mark » Tue Nov 13, 2012 11:10 pm

Hi,

To make this thing work 100% the way you want it, you need to study, study and study again until you know enough about LiveCode to make it so. Surely, we are all here to help you, but we're not going to make the complete project for you.

You could group all controls and place them automatically on new cards (set the backgroundBehavior to true in the properties inspector of the group). Instead of putting each new line before all the other lines, you could use the card number to determine which line to use.

Code: Select all

on mouseUp
   put the num of this cd into myCdNum
   put fld "Description" & tab & fld "Date" & cr into line myCdNum of fld "List"
end mouseUp
You can get the name of a current card with

Code: Select all

  put the short name of this cd into myCdName
and you can replace fld "Description" with myCdName in the script above.

One problem is that we are using the round() function. If the different between a date and today is e.g. 2.4 days, it is rounded to 2 and if the difference is 2.6 days, it is rounded to 3. You could use the trunc() function instead of the round() function or you could use the optional parameter in the round() function like this:

put round((myDate - the seconds)/86400,2) into myDays

to get results with 2 deciments. You can change the 2 into 1 or 3 to get 1 or 3 decimals.

You could also discard the round or trunc function and use div and mod to write a script that displays the remaining time as "2 days, 12 hours and 15 minutes". If you want this, read the dictionary about div and mod. Btw this is also possible with only the trunc function.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Wed Nov 14, 2012 4:25 pm

Hello,

I am only 14 Years old. There is no a place for me to study all this things, and school is alot of time too.
You dont even know what I am trying to do, and this is the most important part of what I am trying to do. This is not all of it, cuz I have to do alot more after it, but I need this thing as a base. for the next things.

I didn't really understand you'r instructions, i understood none of this :

"You could group all controls and place them automatically on new cards (set the backgroundBehavior to true in the properties inspector of the group). Instead of putting each new line before all the other lines, you could use the card number to determine which line to use."

I didn't really understand where you want me to do all this things, when you mean to a button and where for a card. I dont really know what is "(set the backgroundBehavior to true in the properties inspector group) I dont know where to find it and for what button/card to change it..

I would like if you can make me this instructions more easy understanding ,

Thanks alot!

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Wed Nov 14, 2012 4:34 pm

And I dont understand why it's writing to me -15658.648 days left.... Why is it happening ??

Thanks

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Array

Post by Mark » Wed Nov 14, 2012 4:47 pm

Hi,

I didn't mean you to immediately understand that additional remark. I just made some suggestions, implying that some day in the future you will able to do all this.

Just take a few months to read the documentation (see LiveCode's Help menu) and do the tutorials on the RunRev website. Ask questions on this forum if you don't understand something. Don't try to go too quickly. It is really important to take your time for it.

I was 14 in 1987 and was learning HyperCard at the time. All I had was a box with disks and Apple's manual and the HyperCard Help stack (Danny Goodman's book wasn't available here yet and we didn't have internet for another 5 years). I made my first commercially useable office application approximately 6 months later. It took me many nights of studying and lots of trial and error to get where I am now and I still find myself studying and experimenting for hours to solve programming problems.

Good luck.

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Array

Post by Mark » Wed Nov 14, 2012 4:51 pm

Hi,

I'd be happy to answer your questions, but you have never told me what you're using as the date exactly. Only if you tell me what you write in the Date field, I'll be able to answer.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Wed Nov 14, 2012 4:55 pm

What you mean ?

The code for the date or the field the date in her ?

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Wed Nov 14, 2012 5:04 pm

The code im using is :

on openCard
put the long date into field "The Long Date"
set the dateFlag of this stack to true
set the timerFlag of this stack to true
startDate
startTimer
pass openCard
end openCard

on startDate
put the long date into field "The Long Date" card "Category"
if the dateFlag of this stack then send startDate to me in 1second
end startDate

on startTimer
put the time into field "The Long Time" card "Category"
if the timerFlag of this stack then send startTimer to me in 1 second
end startTimer

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Array

Post by sturgis » Wed Nov 14, 2012 5:11 pm

It might be a good idea to start with the basics so you have a better understanding of how all this stuff works together.
Here are a couple links to learning resources.
http://www.runrev.com/developers/docume ... rs-course/
http://lessons.runrev.com

Also, on the toolbar for livecode are 3 buttons.

User samples-- contains stacks uploaded by users so that you can see examples of what others have done.
tutorials -- takes you to .. er.. tutorials
resources -- takes you to other resources including sample stacks and other learning materials.

Having said that, I just looked at the example stack and it works fine. Its very simple and doesn't do things like catch errors in input. But as a quick example it works great.

When you see the number 15659 appear (or 15658.648 if you aren't rounding anymore) it is because you have a blank line in your data. If there is a blank line then when you convert "empty" to seconds it sees the empty as a 0 which is the starting point at which livecode is counting. In this case it is the year 1970. (divide 15658 / 365 and you get 42. Subtract 42 from 2012 and you get 1970.) This can happen if you type into the 2 boxes below and hit enter or return. It can also happen if you type directly into the upper box and hit enter or return, or if you have nothing in the 2 lower boxes and hit enter or return. This type of problem is why you need to go through the tutorials and actually get a better understanding of how everything works together.

As for why 11/14 says 0 days left, while 11/15 says 3 days left, my guess is that the problem is similar. Something is wrong with the data, but without seeing exactly what is in the upper box its hard to define.

0 days left is of course correct since today is the 14th. However, the other thing Mark tried to point out is you should probably use the format that "short date" uses. Your examples list 11/14 and 11/15. Short date is 3 parts not 2. You can get away with just using 2 in some cases but my guess is that there would be instances where this might be unreliable. Better to use the 11/14/12 for Month, Day, Year. (Or however your system defines dates, it is locale specific i believe, which is why Mark waned you to "Put the short date" so that you can see what livecode thinks is the default for your locale. )

The suggestions by about how to actually structure things will only make sense once you understand how livecode apps are structured, and how messages are passed around. You would really be better off starting with the basics and working your way up.

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Wed Nov 14, 2012 5:22 pm

Here,

=)
Attachments
My Field For time.zip
Time
(692 Bytes) Downloaded 486 times

BlaBlaBliBli
Posts: 37
Joined: Sat Oct 06, 2012 12:22 pm

Re: Array

Post by BlaBlaBliBli » Wed Nov 14, 2012 6:15 pm

sturigs alot of thnks for the explantions.

Still, It seems that Mark pretty understand and he helps me alot plus i understand nothing from the explantions the other people made...

So I would like Mark, if you will able to help me a lil bit more :@

Thanks alot!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Array

Post by Mark » Thu Nov 15, 2012 1:00 am

Hi,

You wrote:
What you mean ?
The code for the date or the field the date in her ?
I didn't mean any code. I meant the date.

You also wrote:

Code: Select all

The code im using is :

on openCard
put the long date into field "The Long Date"
set the dateFlag of this stack to true
set the timerFlag of this stack to true
startDate
startTimer
pass openCard
end openCard
In my example, I'm using the short date instead of the long date. The short date is easier if you have to write it manually.

Code: Select all

on startDate
put the long date into field "The Long Date" card "Category"
if the dateFlag of this stack then send startDate to me in 1 second
end startDate
Why would you put the date into a field every second? The date changes only once a day (obviously). Moreover, a field that always contains the current date only exists for cosmetic purposes, because in scripts you'd always use the short or long date. Therefore it is sufficient to update the date only a few times, e.g. when the card opens or when the user presses a button that does calculations involving dates. Better yet: don't display a date field with the current date at all, because most computers show the date in a corner of the screen (e.g. if you move the mouse over the time in the task bar in MS Windows).

Code: Select all

on startTimer
put the time into field "The Long Time" card "Category"
if the timerFlag of this stack then send startTimer to me in 1 second
end startTimer
If you can avoid displaying the time, then avoid it. The time is usually directly available on any computer's screen. Can you make your app without such a field, or if not, what do you need it for?

I've noticed that these scripts have absolutely nothing to do with what we did before. I wonder where you want to go from here.

Since you're not displaying the seconds in the time field, you don't need to update every second. Once a minute is enough. Here's a script that updates the time in exactly the right moment:

Code: Select all

on updateTime
  set the itemDel to colon
  put 60 - item 3 of (word 1 of the long time) into mySeconds
  put the time into fld "Time" // change field name as required
  send "updateTime" to me in mySeconds seconds
end updateTime
Sturgis actually wrote a very useful post. It didn't occur to me that you would have empty lines in field "List". Make sure not to press enter or return after typing a date or a description. If you see an empty line in your List field, you can delete those lines.

You can avoid the problem of empty lines completely if you change the script of the first button a little:

Code: Select all

on mouseUp
   put word 1 to -1 of fld "Description" & tab & word 1 to -1 of fld "Date" & cr before fld "List"
end mouseUp
Sturgis is also right that for my example to work you need to type the date in the Date field in exactly the right way. If you make a mistake, it won't work (which is kind of he curse of the programmer).

One little hint: give your stack names, particularly when you send them to other people. If your stack is called "Untitled 1", you'll run into problems sooner or later. Open the properties inspector of the stack and enter a different stack name.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

Post Reply

Return to “Converting to LiveCode”