• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Jonathan Boykin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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"


 
Carey Brown
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
Jonathan Boykin
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ron McLeod
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes - you're right.
 
Carey Brown
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Replace "==" with ".equals()".
 
Carey Brown
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah, I looked up "Adobe PDF", it is JavaScript, not Java. (FYI)
 
reply
    Bookmark Topic Watch Topic
  • New Topic