I am a beginner in Greenfoot and I am making a mystery, thriller game with backstories and user interaction. I am trying to use string concatenation so that I can ask for the user's name using Greenfoot.ask() and show the text using GreenfootImage, like so:
I could do that in the same method I initiated the variable 'name', but since I have a lot of backstories, I have many many methods, with one method per backstory. I cannot seem to access the variable 'name' in a different backstory, which means I can only mention the player's name once throughout the entire game, unless I ask for it again which is inconvenient.
String name = Greenfoot.ask("Allyson:" + newline + "What's your name?"); setImage(new GreenfootImage("You:" + newline + "Hey. I'm " + name + ". Nice to meet you.", 22, Color.BLACK, Color.WHITE));