Greetings all. I have a project (that works fine BTW), but I believe that there is a more efficient way of accomplishing my objective. Any and all comments are deeply appreciated as I try to become a much more profficient programmer.
Anyway, I have a map of the U.S. (and a few other small countries) on one page. When you roll over an individual state, it is highlighted. At the same time, two text fields are filled with respective Name of State and State's Capital. As I didn't want an individual script with each state (too many scripts), I developed one script using a global property list of the [#state:#capital] as a key.
Problem: Some of the state's names include spaces (i.e. North Dakota). You can't (that I know of) include spaces in lists (unless you use quotes instead of symbols). I chose to use the symbols because I am under the impression that symbols use less memory than actual strings.
This is the behavior that I wrote and placed on each of the fifty sprites:
global gStateCaps
on mouseEnter
--get the current Sprite's Member Name
set currMemName = the name of member (the member of sprite the currentSpriteNum)
--change member name to a symbol and look it up in the global list
--get the current Sprite's Member Name
set currMemName = the name of member (the member of sprite the currentSpriteNum)
--change member name to a symbol and look it up in the global list
--because the list is made up of symbols, not strings
set x = symbol(currMemName)
set newCap = getaProp(gStateCaps, x)
--Change new Capital to a string and delete underscore if one exists by calling
set x = symbol(currMemName)
set newCap = getaProp(gStateCaps, x)
--Change new Capital to a string and delete underscore if one exists by calling
--the 'replaceUnderscore' handler
set newCap1 = replaceUnderscore(String(newCap))
set newCap1 = replaceUnderscore(String(newCap))
--next line does same as above but for state name instead of Capital name
set currMemName1 = replaceUnderscore(currMemName)
set currMemName1 = replaceUnderscore(currMemName)
--put data into appropriate fields
put currMemName1 into field "StateText"
put newCap1 into field "CapitalText"
end mouseEnter
put currMemName1 into field "StateText"
put newCap1 into field "CapitalText"
end mouseEnter
This is the replaceUnderscore script:
on replaceUnderscore (param1)
--This function will search for and delete any underscore ("_") found in a string
set tempString = param1
--This function will search for and delete any underscore ("_") found in a string
set tempString = param1
set newString = ""
repeat with x = 1 to length(tempString)
set tempChar = charToNum(char(x) of tempString)
repeat with x = 1 to length(tempString)
set tempChar = charToNum(char(x) of tempString)
--couldn't seem to get Lingo to check for "_" , so had to convert char to num to recognize it
if tempChar = 95 then
delete char (x) of tempString
set newString = newString&(numToChar(32))
set x = x -1
else
set newString = newString&(char(x) of tempString)
end if
end repeat
return(newString)
end replaceUnderscore
if tempChar = 95 then
delete char (x) of tempString
set newString = newString&(numToChar(32))
set x = x -1
else
set newString = newString&(char(x) of tempString)
end if
end repeat
return(newString)
end replaceUnderscore
I hope all of this makes a little bit of sense, I'm trying to explain it without giving entire scenario. Anyway, like I said, this works great...very fast as well (just dealing with text, so it should be fast). But I do believe that there are many simple factors I may be missing.
BTW, you'll notice no "dot" syntax in anything. That concept hasn't sunk into my peaBrain yet. Running D7 on PC. That about covers it all.
TIA.
Mike 'Spyder' Cash
Video Compositor/Editor by Day
Multi-media programmer by Night
Get your FREE download of MSN Explorer at http://explorer.msn.com
[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list, email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED]) Lingo-L is for learning and helping with programming Lingo. Thanks!]
