Questions to help with my first app

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Questions to help with my first app

Post by magice » Thu Mar 19, 2009 8:34 pm

I have been working with Revolution for 4 days now, and my only complaint is how the documentation is laid out. (more to be read cover to cover then as a reference) I admit I have not yet read all 400 pages, but I have searched them for answers with little results. Here are a couple things I need to know.

How can I dynamically change the choices in an option menu to match values in an array?

Is there any place to write scripts that are not tied to an object but are globally callable from within object scripts. I have some rather long scripts that need to be called from within nested if statements, and I would rather not place the entire scripts in each object if possible.

sorry if these questions are a bit noobish, I'm just not used to this program yet.

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Thu Mar 19, 2009 8:55 pm

Hi magice, I think I can help with your second question, if I understand you correctly: if you mean exactly the same script but called up from multiple objects you can use a custom handler.

So you decide on the name of your handler and this can be placed anywhere, even in the stack script (probably the best place).

A simple example would be, for a button, lets say:

Code: Select all

on mouseUp
---do the stuff specific to this button only
---
---
---
myHandler
---
---
end mouseUp
Then in the stack script:

Code: Select all

on myHandler
---do the stuff thats
--generic to all your objects
end myHandler
It's best to write your custom handler first so that the engine recognises it so you can call it from another object script.

Hope that's helpful for you.
:)

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Thu Mar 19, 2009 11:52 pm

That is exactly what I meant. Thank you very much.....Now if I can just figure out this dynamic options menu thing.

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Fri Mar 20, 2009 12:20 am

Hi magice,
You might also be interested to learn about developments coming up in the forthcoming 3.5 release, like those introduced here http://www.runrev.com/newsletter/februa ... etter2.php and here http://www.runrev.com/newsletter/march/ ... N067S36053 which cover the concept of "behaviors" - where code can be reused in many controls - akin to an "include" file in other environments.
As to the dynamic changing of option menu choices, it's as simple as setting the text of the button. If you have an array with the choices, you may need to convert that (cf 'combine') beforehand, but just

Code: Select all

set the text of button "myOptionMenu" to <<theSingleColumnCRdelimitedList>>
HTH

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Fri Mar 20, 2009 1:47 am

thanks SparkOut I think you have me almost there. I Dumped my array into a new temporary array and combined it using comma. the code looks like this

on populateTarget
global tArray
global tTargetArray
put tArray[2] into tTargetArray
combine tTargetArray using comma
set the text of button "Target" to tTargetArray
end populateTarget

unfortunately when executed I get one single option in the drop down that is a comma delimited list of my array contents. What I am after is for each of those array values to become a separate option in the drop down.

Thanks, You have been a great help

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Fri Mar 20, 2009 2:10 am

nevermind i got it. changed the comma to cr and that fixed it....i feel soooooo dumb

thanks a bunch

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Fri Mar 20, 2009 10:38 am

That's good - but just don't use global variables to do this temporary processing. Your original array may well be, but the temp array that you are combining into the CR delimited list certainly doesn't need to be.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Fri Mar 20, 2009 3:35 pm

You are correct. In the final script it will not be global. However I am temporarily making all of my variables global so that data will be held for debugging purposes. That way if I get unexpected results I can look at it and figure out what I did.
Now on to my next stumbling block.
I need to rearrange my array into numerical order by using the value of the first element of each line while keeping the sub elements of each line intact.
E.G.

array before sorting:
9 , lisa , redhead ,green eyes
5 ,sue , brunette, brown eyes
10 , kim , blonde, blue eyes


array after sorting:
10 , kim , blonde, blue eyes
9 , lisa , redhead ,green eyes
5 ,sue , brunette, brown eyes

(no this is not my array. It is just an example =p)

In C++ I would do this with a for loop using the iteration variable within the array name to specify which array values to compare. Then I would use an if statement within the loop to switch the two array values accordingly. I have played with the repeat command, but without an iteration variable it doesn't seem possible. I also stumbled onto the sort command which, if I am reading the syntax correctly (big if) would seem to be designed to do the process for me. However it does not seem to work. Am I on the right track or is there or is there something else I should be looking at? Again please forgive me for the noobishness of my questions and thanks for your help.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Sat Mar 21, 2009 6:51 am

OK i figured out that the sort command doesn't work with arrays. I had to combine the arrays, do the sort, and then split them back.

Now I have another problem with my earlier created "dynamic drop down menu" Since the contents of the menu is unknown until data fields are filled out by the user, I have no way of knowing the user choices for creating a switch command. Is there any way to reference the item number of the choices as the case condition value instead of the actual choice text? Or, is there a way to use the value of a variable as the case condition value?

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Post by magice » Sat Mar 21, 2009 8:00 am

OK nevermind again....calling a variable in the switch statement doesn't work well, but it works great in nested if statements (For once just like C++)

Post Reply