Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-18-2012, 01:32 PM   PM User | #1
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
New to JS, need script help!

I am creating a script that runs from a program called MaxIm DL. I am new to javascript but am fairly decent at Java. The program only takes JS or VBS as scripting languages. My script is supposed to grab which camera filter the camera is currently using (got CCDCamera from their website) set it to a string, take it again 3 seconds later and set it to another string. then send it though a socket to the server.

I cant get the program to even run in command prompt because it opens and closes immediately. Any help on this would be great!

Here's my code: http://codeviewer.org/view/code:2823

Last edited by GregJ822; 07-18-2012 at 03:21 PM.. Reason: updated code
GregJ822 is offline   Reply With Quote
Old 07-18-2012, 08:26 PM   PM User | #2
oneguy
New Coder

 
Join Date: Jul 2012
Location: Ukraine
Posts: 68
Thanks: 1
Thanked 18 Times in 17 Posts
oneguy is an unknown quantity at this point
Your code contains syntax errors.
Line 379:
Code:
function.prototype.run{
function is a keyword, it can't be used as an identifier. And unexpected { symbol. I don't know what you meant exactly but maybe this:
Code:
Function.prototype.run=function(){
Function is a built-in function and constructor.
Does your environment have a console which shows errors?

Last edited by oneguy; 07-18-2012 at 08:32 PM..
oneguy is offline   Reply With Quote
Old 07-18-2012, 08:29 PM   PM User | #3
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
I edited the old code, so the new code should be there now. consolidated it down. still doesnt run
GregJ822 is offline   Reply With Quote
Old 07-18-2012, 08:39 PM   PM User | #4
oneguy
New Coder

 
Join Date: Jul 2012
Location: Ukraine
Posts: 68
Thanks: 1
Thanked 18 Times in 17 Posts
oneguy is an unknown quantity at this point
Sorry, I left your code open many hours ago and answered only now and didn't notice that you changed the link. Now your code is syntactically valid and I have no idea why it doesn't run. Maybe it's a problem with your environment.
oneguy is offline   Reply With Quote
Old 07-18-2012, 08:43 PM   PM User | #5
oneguy
New Coder

 
Join Date: Jul 2012
Location: Ukraine
Posts: 68
Thanks: 1
Thanked 18 Times in 17 Posts
oneguy is an unknown quantity at this point
Your program has only variable and function declarations, so running it won't have any visible effect.
oneguy is offline   Reply With Quote
Old 07-18-2012, 08:47 PM   PM User | #6
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
Im using "1st javascript editor." ive ran it though command prompt and it closes instantly. Shouldnt it run for 3 seconds atleast?
GregJ822 is offline   Reply With Quote
Old 07-18-2012, 08:56 PM   PM User | #7
oneguy
New Coder

 
Join Date: Jul 2012
Location: Ukraine
Posts: 68
Thanks: 1
Thanked 18 Times in 17 Posts
oneguy is an unknown quantity at this point
Quote:
Originally Posted by GregJ822 View Post
Im using "1st javascript editor." ive ran it though command prompt and it closes instantly. Shouldnt it run for 3 seconds atleast?
No, if this is the full program, it with run and close instantly, because it has only variable and function declarations. The function getRawFilter calls setTimeout but it's never called itself.
oneguy is offline   Reply With Quote
Old 07-18-2012, 08:56 PM   PM User | #8
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
If im running it from localhost shoudnt it send it to the command line?
GregJ822 is offline   Reply With Quote
Old 07-18-2012, 08:59 PM   PM User | #9
oneguy
New Coder

 
Join Date: Jul 2012
Location: Ukraine
Posts: 68
Thanks: 1
Thanked 18 Times in 17 Posts
oneguy is an unknown quantity at this point
Quote:
Originally Posted by GregJ822 View Post
If im running it from localhost shoudnt it send it to the command line?
Sorry, I don't understand the question. What to send to the command line?
oneguy is offline   Reply With Quote
Old 07-18-2012, 09:00 PM   PM User | #10
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
If the host is localhost shouldn't it output whatever "changed" is to the command prompt? Do i need to call getRawFilter from another function in order for it to run?
GregJ822 is offline   Reply With Quote
Old 07-18-2012, 09:12 PM   PM User | #11
oneguy
New Coder

 
Join Date: Jul 2012
Location: Ukraine
Posts: 68
Thanks: 1
Thanked 18 Times in 17 Posts
oneguy is an unknown quantity at this point
Your program doesn't output anything. You declared 3 function but didn't call them. So the interpreter only wrote their code into memory but didn't execute them.
Quote:
Do i need to call getRawFilter from another function in order for it to run?
Your need to execute this statement
Code:
getRawFilter();
You can add it to the program. If you add it to another function which won't be called, this statement won't be executed either.

Last edited by oneguy; 07-18-2012 at 09:16 PM..
oneguy is offline   Reply With Quote
Old 07-18-2012, 09:26 PM   PM User | #12
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,187
Thanks: 59
Thanked 3,995 Times in 3,964 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
On top of that, nowhere in that code do you define what CCDCamera is.

On top of that, nowhere do you invoke the run function.

On top of that...

Well, I really get the feeling we are seeing only a tiny part of your code.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 07-18-2012, 09:27 PM   PM User | #13
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
Here's what i did:

function run(){

function getRawFilter();

var socket = new JSocket();
var port = 3000;
var host = "localhost";

socket.onReady = function(){
socket.connect(host, port);
};

socket.onConnect = function(success, msg){
if(success){
//Send something to the socket
socket.write("connected");
}
else{
alert("Connection failed: " + msg);
}
socket.onData = function(data){
alert("Recieved from socket: " + data);
};
socket.setup("mySocket");
};

if(changed !== null){
socket.send(changed);
}
}

How would i call the run function now? do I need to make another function that just calls it?
GregJ822 is offline   Reply With Quote
Old 07-18-2012, 09:34 PM   PM User | #14
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
This script is being ran from inside another program which on their website says CCDCamera.FilterWheelName is the way to get the filter. Theres a pull down menu from where i can run this script inside of it, so would i even need to define CCDCamera?
GregJ822 is offline   Reply With Quote
Old 07-18-2012, 09:40 PM   PM User | #15
GregJ822
New Coder

 
Join Date: Jul 2012
Posts: 10
Thanks: 1
Thanked 0 Times in 0 Posts
GregJ822 is an unknown quantity at this point
[QUOTE

On top of that, nowhere do you invoke the run function.

[/QUOTE]

how would i invoke the run function? I dont think making another function to call it would do anything since that would just be a never ending chain of invoking methods
GregJ822 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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


All times are GMT +1. The time now is 11:21 AM.


Advertisement
Log in to turn off these ads.