Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenating variables (Help)

Status
Not open for further replies.

SerialCoder

Programmer
Oct 18, 2002
95
US
This should be so simple, but for some reason it is escaping me.

I have a movie (Flash Cards) that on the first Frame sets some global variables:

Code:
On ExitFrame
  Global gNum1,gNum2,gUserAns,gTmp
  Set gUserAns = ""
End ExitFrame

I have the gNum1 and gNum2 randomly generated And gUserAns is being set with the mouseUp behavior of the keys on the (sprite) keypad.

An example Key behavoir:

Code:
On MouseUp 
  Set gTmp = "1"
  Set gUserAns = gUserAns & gTmp
  Set member("UserAns").text = String(gUserAns)
  Play Frame 44
End if

In VB this works i.e. if The user hits key 1 and actuates this behavior, gUserAns will become "1" if the user hits it again, it will concatenate gUserAns with "1" again and gUserAns will become "11"

The way this is right now, I hit the 1 key over and over and never get anything but 1 but when I hit 2 the answer shows as 2. Why wont it concatenate? Am I missing some Director thing?

Thanks in advance...
Dave

 
I don't have the lingo dictionary with me right now, but you could use "put after" to concatenate. Not only is it faster, I think it would be more relaible.
I will check the help ASAP and post.

Mayuresh
 
No, you do not have to put that, the way your doing it works fine generally. PUT AFTER is in verbose lingo, which is silly. May I suggest some things, some which may help with your problem and some which might just save you some time:

-To set a varable, you do not need to use SET, simply
VARIBLE = VALUE

-To initialize variables at the start of a movie, its safer to do so in the On PreparMovie handler. If you initialize globals else where, they can be screwy (trust me, been there).

ON PREPAREMOVIE
global var1,var2
var1 = 5
var2 = 3
END

-Did you include the global statement in the mouseUp script?
A global statement with all the variables called on must be in each handler.

Try thoes things and it should work.
 
fugigoose,

Thanks for the tips. They helped some of my issues (even one that I had not listed in this post), but not the main issue...

Here is an example of where I am at now, bare in mind that it still wont concatenate the string...

On the first frame I have the following script, changed to match your example...

On PREPAREMOVIE
Global gNum1,gNum2,gUserAns,gTmp
gUserAns = ""
member("userAns").text = ""

End PREPAREMOVIE

This worked well.

Somewhere about frame 30 I have the following frame script. It too is doing the trick.

On ExitFrame

Set gNum1 = String(Random(4 + 1)-1)
Set gNum2 = String(Random(4 + 1)-1)

member("Num1").text = gNum1
member("Num2").text = gNum2
member("userAns").text = " "

gUserAns = ""

End ExitFrame

Then on each of the keys of the UI keypad, I have a script something like this:

Property AnsAd

On MouseUp
AnsAd = "7"
Set gUserAns = gUserAns & AnsAd
Set member("UserAns").text = gUserAns
Play Frame 44
End Mouseup

It will change the variable "gUserAns" to 7 and show the result on the screen, When you hit it again, it still shows 7 instead of 77

Any more advice would be greatly appreciated.

 
fugigoose said:
PUT AFTER is in verbose lingo, which is silly.
-------------------------------------------------

I speak from tests.
Check out the openLingo Project.
I took the liberty and here are the speed tests.

-- Speedtest:
-- test of replaceCharBruteforce... 8573ms
-- test of replace... 4499ms
-- test of replace char with put after... 2997ms
-- test of replace char with & strings... 3210ms

So it really ain't that silly.
If you want more detailed information on why it's faster, the project mailing list archives have that.

Mayuresh
 
Typing in verbose lingo will hurt you if you plan on using any other language later on. Also, higher up functions in lingo are in the object form. The reason lingo is powerful is because it can use Object Oriented structures. Really, if you ever hope to make complex games like i'm doing, you won't do it with verbose code. Once you get into parent scripts, its all about OO.

Faster? What about this. I dont even know if this verbose phrase works.

the hieght of the image of the member of sprite 1

sprite(1).member.image.height()

And using the put after and into commands. Psssh, silly.

ex.

put "a" into char 50 of member "text"

or

member("text").char[50] = "a"

See how far you get programming in straight english.
 
What you say is true and I agree with it since I myself stick only to the . syntax. However the speed test results which I posted were done to see the speed difference when dealing with large amounts of text. True that variable concatenation is not huge text manipulation, it's something worht knowing when you're concerned about speed issues.

Mayuresh
 
Glad you see this. I'm concerned more with neatness and efficency. I'd rather not read a novel while I troubleshoot code, but thats just me. I forsee verbose dissapearing entirely from the next version of director. I also think they will eventually change the structure from IF THEN END to the standard { }'s. Back in the day of director 5 & 6, it was all verbose, must've been torture ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top