Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6323031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:26:33+00:00 2026-05-24T16:26:33+00:00

As title says i whant to change my variables in java from my jruby

  • 0

As title says i whant to change my variables in java from my jruby code

To be more specific i have an integer in my Java code which has no value yet, And i whant with my JRuby code give this variable an value, But i have no idea how to do this.

This is how far i got with the JRuby code..

require 'java'
puts "Set player health here"
playerHealth = 3 # Setting player health here!

But have not yet wrote anything in java. This is pretty much all I have so far..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:26:34+00:00Added an answer on May 24, 2026 at 4:26 pm

    From what I understand, you are trying to invoke the JRuby engine from Java, so you could do something like this to modify a Java variable in JRuby:

    import javax.script.*;
    
    public class EvalJRubyScript {
        public static void main(String[] args) throws Exception {
            ScriptEngineManager factory = new ScriptEngineManager();
    
            int playerHealth = 0;
    
            ScriptEngine engine = factory.getEngineByName("jruby");
            ScriptContext context = engine.getContext();
            context.setAttribute("playerHealth", playerHealth, ScriptContext.ENGINE_SCOPE);
    
            try {
                engine.eval("$playerHealth = 42");
                playerHealth = (Integer)context.getAttribute("playerHealth",  ScriptContext.ENGINE_SCOPE);
    
                System.out.println(playerHealth);
            } catch (ScriptException exception) {
                exception.printStackTrace();
            }
        }
    }
    

    Note that in the script playerHealth is a global variable.

    Check out this link for more details if you want to load an external JRuby script rather than evaluating code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty much what the title says really. We have some code that is .NET
The title basically says it all. Suppose I have an element which I want
Just what the title says, I need to change the password for an existing
What the title says. Is there a way to change intellisense settings (intellisense box
Basically, what the title says. I have several properties that combine together to really
Pretty much what the title says. I have a list of Integers like so:
As the title says, what I am trying to do is to have jQuery
As my title says, I have a set property crash problem. Here's the scenario:
It's basically what the title says.. I have a form with a select control
The title pretty much says it all. I have a listview being populated by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.