Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Tried to use JavaScript in an PRG character sheet to calculate the total of a skill getting error

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a Saga Edition character sheet (this is helpful if you know what that is). I pieced together code from other places and thought it should work - I'm getting a syntax error in the oddest place and I don't know why it isn't working. Basically I have several fields being added together. There are two check boxes that if clicked should have a value of 5, if not a value of 0. There is one check box that if clicked should change the formula from an addition scenario to just using a different value on the sheet - that field is called "UTF". Below is the code. I'm trying really hard to learn as I go by learning from other code I find - but it's slow and I usually can't find my errors.

It says the error is "syntax error 7 at line 8"


 
Jonathan Boykin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:No (;) on line 6




Thank you, now it says "syntax error 6 at line 7 and highlights the same field after I added the ";"
 
Carey Brown
Saloon Keeper
Posts: 6768
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was going to ask you if this was JavaScript and not Java, because this is not proper Java syntax.
It should be

[edit]All variables should be lower case.
 
Saloon Keeper
Posts: 2943
373
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:


Even with that change, I can't see how that line is going to work if A and b and numbers and the other variables are strings.  

For example:

Edit: I'm assuming that getField returns a String. - maybe that is a wrong assumption??
 
Carey Brown
Saloon Keeper
Posts: 6768
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Ron McLeod wrote:I can't see how that line is going to work if A and b and numbers and the other variables are strings.  
For example:

It would "work" but perhaps not in the way that Jonathan expects. The 5 + 0 would be operated on first as an integer addition, NOT String concatenation. Then all the other '+' operations are Concatenation because in all cases one of the arguments is a String. So...
"5somethingsomething elseyet something else"
 
Ron McLeod
Saloon Keeper
Posts: 2943
373
Android Eclipse IDE Angular Framework MySQL Database TypeScript Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes - you're right.
 
Carey Brown
Saloon Keeper
Posts: 6768
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
lines 1-6 generate a value in X but X isn't used until line 10. What if you've done all those calculations and ended up at line 13. All that work would have been for naught. Ditto for Z.
 
Carey Brown
Saloon Keeper
Posts: 6768
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Carey Brown
Saloon Keeper
Posts: 6768
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or better yet, put the constant first in case the reference in 'value' is null.
 
Jonathan Boykin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:I was going to ask you if this was JavaScript and not Java, because this is not proper Java syntax.
It should be

[edit]All variables should be lower case.



I made that change and then the addition worked for the two buttons, but not for C, D, or E - they are NOT being included.

So the first issue is getting the C, D, and E to be added too.

Now the second issue is when the button is pushed that should use Formula Z, it doesn't work. Thanks for the help so far - you guys rock.

It must be Java Syntax - I'm doing everything in Adobe Pro PDF software.

The get field command for UTF is grabbing a number that is also calculated using almost identical java; however it doesn't work correctly - but it does have a value in it for now so I can see that it isn't grabbing that value.
 
Jonathan Boykin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:lines 1-6 generate a value in X but X isn't used until line 10. What if you've done all those calculations and ended up at line 13. All that work would have been for naught. Ditto for Z.





In the game, your skill value is either calculated from a series of numbers or if you have a special ability as a Jedi you can instead use your Use the Force rating INSTEAD of the skill. So basically, I need the regular math to work for most situations and then the "override" button for when you aren't really calculating the skill normally but are instead using a different skill's value instead. So yes, all the beginning work could be for nothing if you have the ability to override the normal skill calculation. For me it's not for nothing because this is the way I need it to work.
 
Jonathan Boykin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I now changed the code to this:



Now everything works!!!  I really want to tahank you for your answers and time. This is something I would have struggled with for days and now I know how to do it! I'm just really glad I figured out the pieces you guys hadn't yet and can't think you enough for all the help. I really enjoy learning how to do this kind of stuff, especially when it is a challenge for me.
 
Carey Brown
Saloon Keeper
Posts: 6768
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is more what I had in mind. Don't do a calculation until the point you need it. Also, use .equals().
 
Carey Brown
Saloon Keeper
Posts: 6768
64
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!