Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Storing and Retrieving Strings
Old
Northern
Guest
 
Status:
Posts: n/a
Default Storing and Retrieving Strings - 10-24-2008, 12:59 AM

Hi guys,

I am having a confusing time trying to figure out strings and such. I have searched the forums about this, but it still does not clarify what i want to know.

I'm trying to program something that allows me to store, retrieve and delete information. Like an electronic phone contact book. For example, if i were to type a name followed by the contact number, the information will be stored. So if i press a search button and type in the name the corresponding number will appear. And also if i press delete and type in the name the whole name and number entry will be deleted.

So far what i have done is set up variable strings to ask for name and number. So that when i enter the name, another box will pop up asking for the number. I managed to have another object ask for a name and then it will correspond with the number as an answer. However i can only add in one name and number entry, if i try adding in another one the previous entry disappears.

Any help will be appreciated.

Thanks =D

Last edited by Northern; 10-24-2008 at 01:02 AM.
   
Reply With Quote
Alice is probably the wrong program
Old
DrJim
Guest
 
Status:
Posts: n/a
Default Alice is probably the wrong program - 10-24-2008, 08:11 AM

Unless you must use Alice for this program, I'd suggest another approach. This is going to require quite a bit of string processing and a flexible array/list implementation - neither of which is an area Alice is strong in. In particular, there is no function to extract part of an existing string as a new string - which means your data will be separated into many small pieces that you then must keep track of.

Storing text information is also difficult and requires using the scripting option - which is problematic at best in Alice - but if you use that approach, why not use a scripting language (say Python) directly?

What you want to do also has been done in many "office" programs - Excel, Access, etc. - with excellent results and there are a lot of freeware programs out there also.

If - say for the 3D library or just interest in learning Alice/Java - you do want to stay with Alice, you are going to have to set up some sort of list/array structure to hold the data and then update the data via a separate user interface.

One thing to remember here is that any variable specifically associated with a method will be reset to the default once the method is run. If you want to keep it - you will either have to pass it back to the calling program (i.e., make the method a function) or write the value to a world level variable. The latter, in particular, is not good general programming practice but is the only option in Alice.

Last edited by DrJim; 10-24-2008 at 08:14 AM. Reason: Expanded answer
   
Reply With Quote
Old
Northern
Guest
 
Status:
Posts: n/a
Default 10-24-2008, 09:10 AM

Yeah i have to use Alice to do it. Its just apart of a small project im doing. Been trying to figure it out the whole day today but i keep getting into dead ends and errors.

I have read dickbaldwins tutorials and he mentions doing a telephone book with strings, i thought it be much easier >.<.

I think i will have to use lists/arrays, my knowledge of Alice isn't very good but i'm still learning !

Though if i were to use a list in alice for this project, how would i go about doing that? Do i make the variable list a string and would i be keeping say 4 items on the list as "default string"?

Last edited by Northern; 10-24-2008 at 04:38 PM.
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 10-27-2008, 11:41 AM

I held off posting on this because I was hoping someone else would have some good ideas. Quite frankly, everytime I've started something like this in Alice, I've very quickly switched to another approach - the inability to extract a part of a string makes things quite difficult.

As you suspect, you will have to use a list or an array for the names in the book. You add a name to the list each time you want to update the list and then search for a match with the name you want to look up. I find lists are a little more reliable and since, in Alice, you can only have one dimensional arrays, they don't offer a lot of advantages.

The real problem is that you cannot make the entry in the list contain both the name and the phone number - since to get a match, you'd have to type the name and number in to do the search. If you already do know the number, why bother?

You will have to make another list/array with the phone numbers ordered in the same sequence as the names. Then, when you've found the name, look at the "number list" item with the same index for the phone number and have something in the world say it as a string (if you didn't already store it that way).

The real difficulty is keeping the indicies of the two lists synchronized as new names are added or existing ones are deleted. Not really easy - and one error will ruin the whole "phone book" if you use lists.

Good luck.
   
Reply With Quote
Old
Northern
Guest
 
Status:
Posts: n/a
Default 10-27-2008, 05:25 PM

Thanks DrJim, yeah i was having trouble syncing the two lists together, i think there is something wrong in my coding. I can make it work with just one name and number but it seems to get mixed up when another is added or another after that.
   
Reply With Quote
Phone Book
Old
DrJim
Guest
 
Status:
Posts: n/a
Default Phone Book - 10-28-2008, 05:41 PM

This particular problem has always irritated me, since it shouldn't be very hard - but with Alice, it is. I have a pretty good start - see attached.

The quirks - other than string manipulation - that give problems are that a function can apparently only return a number and that the display of a number as a string is always floating point. Solved most of those - and maybe if you display a number as 321.9999 it won't be too irritating.

Note that you have to be very careful with variable types. Also, though I don't like arrays in Alice very much, that does seem to be the better choice here to keep the name and number arrays synchronized. With lists, I still haven't figured that out.

Looking forward to any feedback as to if you find this helpful.
Attached Files
File Type: a2w Phone Book.a2w (221.8 KB, 99 views)

Last edited by DrJim; 10-28-2008 at 05:47 PM.
   
Reply With Quote
Old
Northern
Guest
 
Status:
Posts: n/a
Default 10-30-2008, 01:23 AM

Hmm you have the question pop up, but you don't have another number question after that.

This is the one i was working on for my assignment. I got the adding, searching and deleting functions to work. but only can input one. When i try using lists, it all fails.

In the program....
The dancer = adding a number
Book = searching
Fireplace = Deleting
Attached Files
File Type: a2w final.a2w (1.60 MB, 74 views)
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 10-31-2008, 04:23 PM

Quote:
Originally Posted by Northern View Post
Hmm you have the question pop up, but you don't have another number question after that.
I just reran the method - but you could easily do the same with a "key pressed" event.

As for a program update - I'd just edit the array. Even with arrays, an update program is messy - and to use the program the user is going to have to have Alice installed anyway. (The export to web page option is much to buggy to support something like this. )
   
Reply With Quote
Saving
Old
zonedabone
Senior Member
 
zonedabone's Avatar
 
Status: Offline
Posts: 577
Join Date: Nov 2008
Location: In the interwebs
Default Saving - 11-06-2008, 05:05 PM

Would there be a way to make alice save to a file all of the strings?


'Apple Macintosh' - An anagram of 'Complaints Heap'

M.A.C.I.N.T.O.S.H. - Machine Always Crashes, If Not, The Operating System Hangs.

You're *such* a mac person.
   
Reply With Quote
Old
DrJim
Guest
 
Status:
Posts: n/a
Default 11-07-2008, 12:52 PM

Quote:
Originally Posted by zonedabone View Post
Would there be a way to make alice save to a file all of the strings?
In principle, yes - but it would be messy. You would (1) have to first use relatively large arrays that would be mostly empty (you can't change an array size during program execution), (2) have to write a method to update the arrays from the user input and (3) write another pair of methods to save the updated data and automatically load that last data the next time the programs starts.

This could be done - but item (3) is particularly difficult in Alice, although it is quite easy with other tools. Alice just isn't the right tool for this application.
   
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.