Mythruna

Modder's Workbench => Scripting => Topic started by: Michael on December 19, 2012, 07:53:43 PM



Title: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on December 19, 2012, 07:53:43 PM
Ok, I am making a text adventure with actual knowledge, as you know I am beginner (or some may know.) I have made a GUI window JFrame swing thing.

Now the problem. Putting the text and features INTO the window. I have heard that you use the JLabel to show text on the window (GUI) but I cannot do so, because the screen is blank:

(http://i.imgur.com/wlMJh.jpg)

I do have the game running in the background (on the console) but hidden. Here is my code:

Quote

Game.java
Code:
package main;

/*
 * Shzylo's Text Adventure v1.0
 *
 */
import java.util.Scanner;
import java.awt.*;

import javax.swing.*;
 
public class Game extends Variables implements Runnable {
private static final long serialVersionUID = 1L;

private JFrame frame = new JFrame();

public int height = 350;
public int width = 650;

    public Game() {
    Dimension size = new Dimension( width, height);
    setPreferredSize(size);
    }
   
    public static void main(String[] args) {
    Game game = new Game();
    game.frame.setResizable(false);
    game.frame.setTitle("Shzylo's Text Adventure v0.1 BETA");
    game.frame.add(game);
    game.frame.pack();
game.frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
game.frame.setLocationRelativeTo(null);
game.frame.setVisible(true);

Main.start();
    }
   
public void run() {
while(running) {
}

}
   
}


Variables.java
Code:
package main;

import java.awt.Canvas;
import java.util.Scanner;
 
public class Variables extends Canvas {
private static final long serialVersionUID = 1L;

    static Scanner i = new Scanner(System.in);
    public static String string = "";
    private Thread thread;
   
    protected static boolean running = false;
     
    public static void sleep() {
        try {
            Thread.sleep(1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
     
    public static void space() {
        System.out.println("");
    }
}


Main.java
Code:
package main;

import javax.swing.JLabel;
 
public class Main extends Variables {
private static final long serialVersionUID = 1L;
static int x = 0;
static int y = 0;

static int stickValue = 1;
static boolean stickObject = false;

    public static void start() {
    running = true;
        System.out.println("You wake up lost, washed ashore on a beach. All you see in sight is a stick, a rock, and lots of sand.");
        System.out.println("Where would you like to go? North, South, East, West");
        System.out.println("type 'help' if you need help.");
        string = i.nextLine();
       
        do {
        if(string.equalsIgnoreCase("north")) {
            north(); 
             
        } else if(string.equalsIgnoreCase("south")) {
            south();
           
        } else if(string.equalsIgnoreCase("east")) {
            east();   
             
        } else if(string.equalsIgnoreCase("west")) {
        stickValue--;
       
        if(stickValue == 0) {
        stickObject = true;
        if(stickObject = true) {
        west();
        }
        }
           
        } else if(string.equalsIgnoreCase("help")) {
            help();
       
        } else {
        System.out.println("I do not recognize that command..");
        sleep();
        System.out.println("Please choose an action:");
        string = i.nextLine();
       
        }
        } while(x == y);
    }
     
    public static void north() {
        System.out.println("You have traveled north into a forest, where you see a turtle resting on a rock, nothing special in this direction.");
        sleep();
        System.out.println("Please choose an action:");
        string = i.nextLine();
    }
    public static void south() {
        System.out.println("I wouldn't go that way, there is an aweful lot of water there.");
        sleep();
        System.out.println("Please choose an action:");
        string = i.nextLine();
    }
    public static void east() {
        System.out.println("Oh, a snake, it's staring and hissing at you. I would get some defense before I go there.");
        sleep();
        System.out.println("Please choose an action:");
        string = i.nextLine();
    }
    public static void west() {
        System.out.println("I see rope, and some bass in a small pool of water");
        sleep();
        System.out.println("Please choose an action:");
        string = i.nextLine();
    }
    public static void help() {
    System.out.println("Where would you like to go? North, South, East, West");
    sleep();
    string = i.nextLine();
    }
   
   
    public static void stop() {
    running = false;
    }
}

Want to test it yourself? go ahead: http://www.mediafire.com/download.php?9l4gea5ty8ms80l
Source code to check it yourself? go ahead: http://www.mediafire.com/download.php?dsz4d58za5rzbpv


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on December 20, 2012, 06:55:04 AM
You will find this much easier if you do it as a command line based app now and worry about a real window later.

I'm going to be exceedingly generous and show a block of code for reading commands from the command line:

Code:
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
String line = null;
while( (line = in.readLine() ) {
    System.out.println( "You entered:" + line );
}

In a simple text adventure, that is your game loop.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Moonkey on December 20, 2012, 12:06:35 PM
Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Moonkey on December 20, 2012, 12:08:32 PM
Oh, and it's a bit confusing. And it locked up when I typed west at the rope part. Lol.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Sean on December 20, 2012, 01:00:20 PM
Listen to Paul, text adventures should be done in the command prompt.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Iggyjeckel on December 20, 2012, 01:01:28 PM
With programa in c++ if it asks for an integer value, and you put lets say 'y' it breaks it. One of the things i noticed from programming so far is "program for the trolls....they will try anything and everything to break your program" lol


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on December 20, 2012, 01:54:12 PM
Ah, I see you are using Scanner to read std in.  That's ok, too.  Don't worry about a GUI yet.  The whole point of the text adventure exercise is to not have to worry about that stuff.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on December 20, 2012, 02:29:32 PM
i'm trying to get ahead of myself... oh boy. :)


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on December 20, 2012, 03:07:43 PM
Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)

Not my fault, mediafire does that itself :P


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Moonkey on December 20, 2012, 04:45:22 PM
Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)

Not my fault, mediafire does that itself :P
I've downloaded tons of Minecraft mods from Mediafire that give me a .zip and not a .ZIP... Oh well *goes away*


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on December 20, 2012, 05:05:53 PM
Don't upload your file with a capital ZIP. Else, winrar can't open it and gives an error. (I had to change the ZIP to a zip.)

Not my fault, mediafire does that itself :P
I've downloaded tons of Minecraft mods from Mediafire that give me a .zip and not a .ZIP... Oh well *goes away*

The real issue is that your system doesn't recognize ZIP as zip.  Windows is case insensitive so there is something funny with that software's setup.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on December 20, 2012, 05:15:21 PM
I do
RIGHT CLICK -> New -> Compressed (zipped) folder


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on December 20, 2012, 08:01:54 PM
I do
RIGHT CLICK -> New -> Compressed (zipped) folder

Yeah, this time I wasn't picking on you.  .zip, .ZIP, .ZiP, .Zip should all be valid zip files on Windows.  If not then something is messed up on the person's computer who is trying to extract them.  Or the files are not really . zip at all.

On Windows you shouldn't have to use WinRAR anyway since windows can handle .zip files natively.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Iggyjeckel on December 20, 2012, 08:30:42 PM
Unless its "old" windows lol


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on December 20, 2012, 09:11:05 PM
Unless its "old" windows lol

Like, earlier than Windows XP.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on December 20, 2012, 09:14:44 PM
Unless its "old" windows lol

Like, earlier than Windows XP.
Windows 98 - from the future or the past?


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Moonkey on December 20, 2012, 09:42:40 PM
Sorry, Paul, but I find Winrar alot more fun to use. *winks*

Edit: I bet barely anyone here has Windows 8. (Including myself)


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: FutureB on December 20, 2012, 10:32:45 PM
i tried windows 8 like 6 months ago and gave up on it because it wasn't ready, i have 3 friends with it now and they seem to like it but are always being annoyed about something or rather so idk if ill switch i might just wait until they stop supporting windows 7


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on December 20, 2012, 10:47:50 PM
i tried windows 8 like 6 months ago and gave up on it because it wasn't ready, i have 3 friends with it now and they seem to like it but are always being annoyed about something or rather so idk if ill switch i might just wait until they stop supporting windows 7

To me it looks like Microsoft got tired of getting picked on for shoving a desktop OS onto phones.  So instead, they now shove a phone OS onto desktops.

The most positive praise I've seen seems to think Microsoft has a vision where the computer is more an appliance like phones and stuff.  The thing is, in that case the OS doesn't really matter... users don't care what operating system their blu-ray player has, for example, as long as it runs blu-ray disks, connects to the web, etc..

Content is the new market.  Apple saw this which is why iTunes, app store, etc..  And Amazon releasing a tablet was so obviously a good idea that the universe would have imploded if they hadn't done it.  My Kindle Fire could not be a more convenient device to use... it's like a two way street giving me content and sucking cash directly from my wallet... and it's all good either way.  In four or five years, if you don't control a content stream then you are a bit player just supplying things to the big guys.  I think even Apple might be heading to a point where the fact that they produce a phone is only ancillary.  They fight commoditization at every turn but it's kind of inevitable.  The more pure the content delivery endpoint gets the less the user cares about what particular brand of underlying thing it's running.  "Does it have Angry Birds?!?!"  "What button do I push for Netflix?"  etc.

Hey, I took an Unn thread off topic.  ;)


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on December 20, 2012, 11:02:37 PM
i tried windows 8 like 6 months ago and gave up on it because it wasn't ready, i have 3 friends with it now and they seem to like it but are always being annoyed about something or rather so idk if ill switch i might just wait until they stop supporting windows 7

To me it looks like Microsoft got tired of getting picked on for shoving a desktop OS onto phones.  So instead, they now shove a phone OS onto desktops.

The most positive praise I've seen seems to think Microsoft has a vision where the computer is more an appliance like phones and stuff.  The thing is, in that case the OS doesn't really matter... users don't care what operating system their blu-ray player has, for example, as long as it runs blu-ray disks, connects to the web, etc..

Content is the new market.  Apple saw this which is why iTunes, app store, etc..  And Amazon releasing a tablet was so obviously a good idea that the universe would have imploded if they hadn't done it.  My Kindle Fire could not be a more convenient device to use... it's like a two way street giving me content and sucking cash directly from my wallet... and it's all good either way.  In four or five years, if you don't control a content stream then you are a bit player just supplying things to the big guys.  I think even Apple might be heading to a point where the fact that they produce a phone is only ancillary.  They fight commoditization at every turn but it's kind of inevitable.  The more pure the content delivery endpoint gets the less the user cares about what particular brand of underlying thing it's running.  "Does it have Angry Birds?!?!"  "What button do I push for Netflix?"  etc.

Hey, I took an Unn thread off topic.  ;)

Aww, your first turn-off-topic. I'm so proud of you :') they grow up so fast..


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Moonkey on December 21, 2012, 08:05:19 PM
Grow down*


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on December 21, 2012, 09:15:35 PM
lol


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on January 14, 2013, 08:53:44 PM
You will find this much easier if you do it as a command line based app now and worry about a real window later.

I'm going to be exceedingly generous and show a block of code for reading commands from the command line:

Code:
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
String line = null;
while( (line = in.readLine() ) {
    System.out.println( "You entered:" + line );
}

In a simple text adventure, that is your game loop.

I am just pulling this back up, sorry for bugging you though about this. That loop never did work. here is code:

Code:
package main;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Game {

static int x = 0;
static String user = null;

public static void main(String[] args) {

BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
String line = null;
while( (line = in.readLine() ) {
   System.out.println( "You entered:" + line );
}
}
}
it will give me error on line = in.readLine() saying to add the null pointer exception, then it says that it cannot convert from a String to a boolean. :-\


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on January 14, 2013, 09:12:35 PM
My code should work find but you have to do it as:
while( (line = in.readLine()) != null )

I was typing from memory.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on January 14, 2013, 09:14:22 PM
And I have no idea what you are talking about with "add the null pointer exception".  That's ridiculous or you are in error.  Maybe you remembered the error message wrong?

It might have said something about IOException... which is a try/catch that should wrap this whole code block.  Or just let main throw Exception.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on January 14, 2013, 09:17:55 PM
My code should work find but you have to do it as:
while( (line = in.readLine()) != null )

I was typing from memory.
Ah, ok I got it, thank you for the quick reply and sorry  :-[

EDIT:
Quote from: pspeed
And I have no idea what you are talking about with "add the null pointer exception".  That's ridiculous or you are in error.  Maybe you remembered the error message wrong?

It might have said something about IOException... which is a try/catch that should wrap this whole code block.  Or just let main throw Exception.
It doesn't give the message anymore. It gave me the option of adding "throw IOException" or "surround with try/catch" and i chose IOException.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on January 14, 2013, 09:36:57 PM
Heh, figured out the BufferedWriter all by myself :)

Code:
BufferedReader in = new BufferedReader( new InputStreamReader(System.in) );
It seemed logic to turn BufferedReader into BufferedWriter, and InputStreamReader to OutputStreamWriter and System.in to System.out xD
Code:
BufferedWriter out = new BufferedWriter( new OutputStreamWriter(System.out) );
I believe this isn't right though...
Quote
while( (in.readLine() ) != null) {
         out.write("Start"); {
            System.out.println("Hello World!");
         }
      }
_Don't tell me though!_


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: pspeed on January 14, 2013, 09:49:22 PM
The real question is why you are trying to do that when you can already write to the console using System.out.println().

If you wanted to have your own writer then PrintWriter is better... then you can do out.println(), etc.

What you have should work other than the strange nested braces that don't do anything and have the System.out.println() in them.


Title: Re: OFF TOPIC SCRIPTING (cannot find essential help elsewhere)
Post by: Michael on January 15, 2013, 02:26:39 PM
I was trying to make it like the java.util.Scanner but i guess the scanner is all I can use xD i was tired at the time :)