Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 22nd, 2024, 9:12 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Functions problem
PostPosted: July 21st, 2011, 10:21 am 
Offline

Joined: July 5th, 2011, 2:51 pm
Posts: 44
Opus: Opus Pro 8
OS: Windows 10; 64-bit operating system
System: Intel(R) Core(TM) i5 CPU, 4.00GB (RAM)
Hi, noob here!
So this is my plan:

generate two random numbers, display them in two different text boxes. (got that working)

generate 4 random calculations like "+", "-", "*", "/"

i did this:

var calcRandom = random(4)
function fCalc ()

if (calcRandom == 1)
{
fCalc ("+")
calctext.SetSelection(0,-1)
calctext.ReplaceSelection(calcRandom)
}

the function "fCalc" that i declared seems to have an expression error. but i looked up the function's syntax and there is no problem.


Top
 Profile  
 
 Post subject: Re: Functions problem
PostPosted: July 21st, 2011, 12:34 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Quote:
the function "fCalc" that i declared seems to have an expression error
Are you showing the code for the function fCalc?

If so, a couple thoughts. One, you need {} to start and end the code for the function. Two, are you calling fCalc() from within fCalc?

- - - - - - - -
It is really difficult to solve this when seeing only part of the code, or worse... seeing a piece of code here and another fragment there.
Suggest:
1) use the Code Box to show your scripting when posting
2) when you post code, make sure you provide enough code so that it makes sense.
3) copy and paste code exactly as you are using it, testing it (e.g., maybe you have the '{}' brackets noted above, but you are not showing them here... and then I'm wasting my time picking that out as part of the problem?)

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Functions problem
PostPosted: July 21st, 2011, 12:42 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Quote:
the function "fCalc" that i declared seems to have an expression error
If you are not showing the code for fCalc() here...

...then I assume you have left out the part where you expect the function to receive a parameter. For example:
Code:
function myDoThis( parameterA )
{
var myDistance = 20 * parameterA ;
RectangleObj1.Move(myDistance, 0, 2) ;
}

//the above function will be called elsewhere as follows
myDoThis( "12" ) ;  //the parameter can also be a variable or an expression of course

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Functions problem
PostPosted: July 21st, 2011, 12:57 pm 
Offline

Joined: July 5th, 2011, 2:51 pm
Posts: 44
Opus: Opus Pro 8
OS: Windows 10; 64-bit operating system
System: Intel(R) Core(TM) i5 CPU, 4.00GB (RAM)
after i posted this i realised i did not use the correct syntax for to declare my function.. :oops:

so i fixed it but now i am trying to tell a function that is is supposed to do a calculation like a + or -

//// ////
var calcRandom = Math.random(4)

function fCalc()
{
}

//statement for calculations//

if (calcRandom == 1)
{
fCalc ("+") //how to tell fCalc that + is gonna do a plus calculation??
}


Top
 Profile  
 
 Post subject: Re: Functions problem
PostPosted: July 21st, 2011, 12:58 pm 
Offline

Joined: July 5th, 2011, 2:51 pm
Posts: 44
Opus: Opus Pro 8
OS: Windows 10; 64-bit operating system
System: Intel(R) Core(TM) i5 CPU, 4.00GB (RAM)
because there will be random calculations generating like - or * when i click


I know im asking stupid questions, I have never in my life done any kind of programming or scripting so stil very stupid with the whole deal :!:


Top
 Profile  
 
 Post subject: Re: Functions problem
PostPosted: July 21st, 2011, 1:38 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
We all start somewhere :-)

1. Learn to use debug: http://www.live.interaktiv.co.uk/index. ... Itemid=166

2. Math.random will generate a number between 0 and 1. (The help is wrong!)

3. String.random will generate a number between 0 and limit.

4. The use of var outside of a function is moot as it only used to scope the variable locally inside of a function.

5. Any JavaScript book up to version 1.2 will help with the basics.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Last edited by mackavi on July 21st, 2011, 2:00 pm, edited 1 time in total.

Top
 Profile Visit website  
 
 Post subject: Re: Functions problem
PostPosted: July 21st, 2011, 1:44 pm 
Offline

Joined: July 5th, 2011, 2:51 pm
Posts: 44
Opus: Opus Pro 8
OS: Windows 10; 64-bit operating system
System: Intel(R) Core(TM) i5 CPU, 4.00GB (RAM)
:) :mrgreen:


Top
 Profile  
 
 Post subject: Re: Functions problem
PostPosted: July 21st, 2011, 2:34 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Quote:
so i fixed it but now i am trying to tell a function that is is supposed to do a calculation like a + or -
It seems your approach is to 'piece together' a mathematical expression... a + b, or in other cases a / b etc.

However, I suggest you try this more directly using simple logic.

For example, IF case1... myresult = a + b ;
IF case2... myresult = a - b ;
etc.
etc.

I outlined it above and leave it to you to figure out the syntax and the logic flow.

An alternative approach (rather than listing a series of if statements) is to use Opusscript's switch case function. Achieves the same thing with easier (IMO) code.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject: Re: Functions problem
PostPosted: July 22nd, 2011, 9:34 am 
Offline

Joined: July 5th, 2011, 2:51 pm
Posts: 44
Opus: Opus Pro 8
OS: Windows 10; 64-bit operating system
System: Intel(R) Core(TM) i5 CPU, 4.00GB (RAM)
That makes so much more sence and now that i think about it i was a moron for not thinking of it...thank you :? :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 38 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group