Replace Problem - Printable Version
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Replace Problem (/showthread.php?tid=98078)
Replace Problem by Spunky on 08-02-2011 at 08:21 PM
I'm having trouble with the following code:
If x is set to "push", "join", "reverse", "pop" or any other array method then I get "Object Expected" error and it traces:
Any ideas why? Everything should just be treated as a string I'm probably being stupid
RE: Replace Problem by matty on 08-02-2011 at 08:33 PM
Couldn't you use .toString()?
RE: Replace Problem by Spunky on 08-02-2011 at 08:36 PM
Doesn't work. I get the same results
RE: Replace Problem by Eljay on 08-02-2011 at 08:48 PM
How was y defined?
RE: Replace Problem by whiz on 08-02-2011 at 08:48 PM
I'm assuming it's because, for objects, foo.bar is the same as foo["bar"]. Seems calling ["foo"], where foo is an array method, always seems to do this.
RE: Replace Problem by Spunky on 08-02-2011 at 08:52 PM
I'll try shortly. If that does fix it, it's a bit sloppy, but I want it working. For the purposes of the script, it doesn't really cause any errors, Just don't want all that in the debug =/
EDIT: Nope can't seem to do that without breaking the script. I need the value related to x from y
Arrays are Objects
RE: Replace Problem by Eljay on 08-02-2011 at 09:00 PM
Well yeah, but the in keyword returns true because of all the built-in Array functions. Try using:
RE: Replace Problem by Spunky on 08-02-2011 at 09:02 PM
Works perfect No dodgy try... catch statements for me
RE: Replace Problem by Matti on 08-03-2011 at 08:50 AM
How is y defined? If you're storing values in an Array variable using string keys, then you're storing them as properties in the Object and not as elements in the Array.
It'd also help if you gave your variables decent names. How will you know what x and y were when you look at your code again in a few months?