I am learning Java programming and recently have been learning a ton about variables. It's very simple stuff but I am just wondering if anyone could give some suggestions on how to clean this up, it looks kind of messy. Even some tips on what else I could add to it to kind of expand my learning would be helpful. :)
Here's the code:
[code]class Squareroot {
public static void main(String [] args) {
int letterX = 225;
System.out.println("Integer X's square root is "
+ letterX
+ "."
);
int letterY = 412;
System.out.println("Intergy Y's square root is "
+ letterY
+ "."
);
}
}[/code]
Actually I forgot to add the code that calculates the square root. Thanks for pointing that out.
Here's the finished code:
classSquareroot{publicstaticvoidmain(String[]args){intletterX=225;System.out.println("The square root of "+letterX+" is "+Math.sqrt(letterX)+".");intletterY=412;System.out.println("The square root of "+letterY+" is "+Math.sqrt(letterY)+".");}}
I know this probably isn't useful to any of you, but I was asking how to clean it up and it got answered. Progammer found a little mistake I did so I figured I would just fix my mistake and correct it so you aspiring programmers don't think what I did was correct. O_O
boolmain(){intletterX;intletterY;letterX=225;letterY=412;UIDisplayMessage(PlayerGroupAll(),c_messageAreaSubtitle,(StringToText("The square root of ")+IntToText(letterX)+StringToText(" is ")+IntToText(SquareRootI(IntToFixed(letterX)))+StringToText(".")));UIDisplayMessage(PlayerGroupAll(),c_messageAreaSubtitle,(StringToText("The square root of ")+IntToText(letterY)+StringToText(" is ")+IntToText(SquareRootI(IntToFixed(letterY)))+StringToText(".")));returntrue;}
Looks virtually the same eh? Major difference is Galaxy is stingy, and java is spoiling. Boolean function, cuz i'd rather not import with MPQeditor.
I just learned Java this year and am now writing a 2d rpg engine in it. A great resource is the Java Tutorial (by oracle the company that created java) you can find it here http:download.oracle.com/javase/tutorial/ it has very detailed coverage of all the basics of Java including object oriented programing, creating GUI, Best practices, Networking and a bunch of other stuff.
@SouLCarveRR: Go
the so called "main" function that is called on map start is this one -> void InitMap ()
voidInitMap(){InitLibs();InitTriggers();}
That's what it'll look like if you used any library function inside Triggers, it'll automatically generate InitLibs() inside of it, and adds InitTriggers() if you made a trigger.
My codes needs to be triggered through InitTriggers() which calls a constructor to add a thread containing my function "bool main()"
I should've coded it to run without triggers, and just within "void InitMap ()" to actually mimic the posted Java code. But i implemented it through the custom script action, to avoid having to import a new MapScript.galaxy file. The galaxy editor likes to overwrite that file, if it doesn't like what you did.
Which means a more proper representation in Galaxy would be:
voidInitMap(){intletterX;intletterY;letterX=225;letterY=412;UIDisplayMessage(PlayerGroupAll(),c_messageAreaSubtitle,(StringToText("The square root of ")+IntToText(letterX)+StringToText(" is ")+IntToText(SquareRootI(IntToFixed(letterX)))+StringToText(".")));UIDisplayMessage(PlayerGroupAll(),c_messageAreaSubtitle,(StringToText("The square root of ")+IntToText(letterY)+StringToText(" is ")+IntToText(SquareRootI(IntToFixed(letterY)))+StringToText(".")));}
There are include files too, but lets not nitpick. xD
The way to "run" this code would be to create 2 Custom Script Actions (could be 1, but cleaner looking with 2).
First one you put:
returntrue;}
second one you put:
boolname_of_your_function(){// Your code here
no need to put in "return true;}" because the previous function that you closed with your first action already generated that for you. Hope I didn't miss anything.
Very Nice thats the kinda stuff I like to see to learn. Thanx much so far I really havent done a single thing in script yet.
I have some questions about this is anybody is willing to answer. I've changed a couple things, to better illistrate my questions.
voidInitMap(){InitLibs();InitTriggers();'This is to load gui triggers or what? (How do I call a gui trigger or gui function?) DoTheMath(); 'Isthishowyouwouldcalltorunascriptedfunction?}voidDoTheMath(){intletterX;intletterY;letterX=225;letterY=412;UIDisplayMessage(PlayerGroupAll(),c_messageAreaSubtitle,(StringToText("The square root of ")+IntToText(letterX)+StringToText(" is ")+IntToText(SquareRootI(IntToFixed(letterX)))+StringToText(".")));UIDisplayMessage(PlayerGroupAll(),c_messageAreaSubtitle,(StringToText("The square root of ")+IntToText(letterY)+StringToText(" is ")+IntToText(SquareRootI(IntToFixed(letterY)))+StringToText(".")));}returntrue;'(whataretheselasttwolineshereforthe"function"isendedalready?)}
I kinda wrote my questions in the code as comments... BTW what are the comment and function calling syntax?
First I would like to say, I am sorry if I annoy you with these questions, I don't know an actual programming site that will help you with your questions. I just decided to post here because I know some of you can do some stuff like llou and onisagi. I think from progammers video's he does it too. :-)
I have a couple questions for any of you Java programmers. First, I'm reading about pasting Strings together using "+." Why would I need to do that, like what's the purpose of it. I guess right now it seems so useless.. Is it just to keep your code a bit more organized so one String variable does not get too over chaotic?
Second question. If I make a box that holds text in a video game like how do you know when to do /n? Like in Fallout 3 they have a certain amount of text before they do a /n. I know they don't use Java in their game, obviously. But surely they use some type of "/n" command. Here's an example if this wasn't understandable:
String showText = "The black-toast intolerant fox was furious. He couldn't drink milk and that upset him greatly. What would Mr. Fox do here now?"
^ In java there is no, "auto paragraph," so how do you know when to start a new line or "/n?"
Is there a way to disable the parsing error? It does not harm my program and not matter how much I fix it it won't go away. It's just annoying, not much of an issue."
I am learning Java programming and recently have been learning a ton about variables. It's very simple stuff but I am just wondering if anyone could give some suggestions on how to clean this up, it looks kind of messy. Even some tips on what else I could add to it to kind of expand my learning would be helpful. :) Here's the code:
[code]class Squareroot { public static void main(String [] args) { int letterX = 225; System.out.println("Integer X's square root is " + letterX + "." ); int letterY = 412; System.out.println("Intergy Y's square root is " + letterY + "." ); } }[/code]
Well if you dont want it looking so messy....
Thats about as clean as it gets
Who wants to translate that into galaxy
@SouLCarveRR: Go
thanks. How did you do that formatting?
Do you actually calculate the square root of those ? I assume the output would be 225 and 412.
About formatting, its called the code block, if the markup is wikicreole (which is by default), do this
<<code >>
Your code here
<</code>>
OR
<<code galaxy>>
Your code here
<</code>>
@progammer: Go
Actually I forgot to add the code that calculates the square root. Thanks for pointing that out.
Here's the finished code:
I know this probably isn't useful to any of you, but I was asking how to clean it up and it got answered. Progammer found a little mistake I did so I figured I would just fix my mistake and correct it so you aspiring programmers don't think what I did was correct. O_O
It seems very odd to me that your calling the class itself squareroot when your not making an actuall function to do the calculations
@SouLCarveRR: Go
I don't know how to do functions yet. I am just a beginner at this, as in started 4 days ago. =)
@StatusQ3: Go
StatusQ3 has earned the Progammer achivements: Spelling Progammer's name right for the very first time.
Anyway, good luck with java and welcome to programming.
@SouLCarveRR: Go Comin' right up.
Looks virtually the same eh? Major difference is Galaxy is stingy, and java is spoiling. Boolean function, cuz i'd rather not import with MPQeditor.
I just learned Java this year and am now writing a 2d rpg engine in it. A great resource is the Java Tutorial (by oracle the company that created java) you can find it here http:download.oracle.com/javase/tutorial/ it has very detailed coverage of all the basics of Java including object oriented programing, creating GUI, Best practices, Networking and a bunch of other stuff.
@DirectorOfTheUED: Go
Java originated from Sun Microsystems. But good resource, Oracle acquired Sun, which is why they offer support for java.
its a pitty Oracle acquired Sun. i feel like Oracle are just going to let java rot and not maintain it.
and java fx isnt that great
@onisagi: Go
I regards to this galaxy scipting...
does the bool "main" does that run on load... or do you have to call it?
Like if I added that script to my map would it run on map load?
@onisagi: Go I love you.
It'd only run on the map load if you put the call to it in the map init function. You still have to call to it in order to use it and stuff.
@Sixen: Go
Ah yeah so the map doesnt use a "main" sixen is there a reference anywhere to this ..... map init function anywhere on the site?
@SouLCarveRR: Go the so called "main" function that is called on map start is this one -> void InitMap ()
That's what it'll look like if you used any library function inside Triggers, it'll automatically generate InitLibs() inside of it, and adds InitTriggers() if you made a trigger.
My codes needs to be triggered through InitTriggers() which calls a constructor to add a thread containing my function "bool main()"
I should've coded it to run without triggers, and just within "void InitMap ()" to actually mimic the posted Java code. But i implemented it through the custom script action, to avoid having to import a new MapScript.galaxy file. The galaxy editor likes to overwrite that file, if it doesn't like what you did.
Which means a more proper representation in Galaxy would be:
There are include files too, but lets not nitpick. xD
The way to "run" this code would be to create 2 Custom Script Actions (could be 1, but cleaner looking with 2).
First one you put:
second one you put:
no need to put in "return true;}" because the previous function that you closed with your first action already generated that for you. Hope I didn't miss anything.
@onisagi: Go
Very Nice thats the kinda stuff I like to see to learn. Thanx much so far I really havent done a single thing in script yet.
I have some questions about this is anybody is willing to answer. I've changed a couple things, to better illistrate my questions.
I kinda wrote my questions in the code as comments... BTW what are the comment and function calling syntax?
Hey guys,
First I would like to say, I am sorry if I annoy you with these questions, I don't know an actual programming site that will help you with your questions. I just decided to post here because I know some of you can do some stuff like llou and onisagi. I think from progammers video's he does it too. :-)
I have a couple questions for any of you Java programmers. First, I'm reading about pasting Strings together using "+." Why would I need to do that, like what's the purpose of it. I guess right now it seems so useless.. Is it just to keep your code a bit more organized so one String variable does not get too over chaotic?
Second question. If I make a box that holds text in a video game like how do you know when to do /n? Like in Fallout 3 they have a certain amount of text before they do a /n. I know they don't use Java in their game, obviously. But surely they use some type of "/n" command. Here's an example if this wasn't understandable:
String showText = "The black-toast intolerant fox was furious. He couldn't drink milk and that upset him greatly. What would Mr. Fox do here now?"
^ In java there is no, "auto paragraph," so how do you know when to start a new line or "/n?"
Heres another one:
Is there a way to disable the parsing error? It does not harm my program and not matter how much I fix it it won't go away. It's just annoying, not much of an issue."
look up "java line return syntax" on google
and I know nothing about error debugging in java