• What do you need help with? Version 1
    5,001 replies, posted
[QUOTE=CommanderPT;26355548]I forgot what it is called but I hope somebody can tell me. Something to do with random integers. New rand = random.nextint(6) or something. I need it for a dice. I can't find out how to type it properly. Edit: Found it. [editline]28th November 2010[/editline] import java.util.Random; public class dice { public static void main (String[] arg) { int t = 0; Random rand = new Random (); for (int counter=0; counter<=10; counter++) { t++; rand.nextInt(6); System.out.println(rand); } } } I want to print out the value that rand gets every time the for loops. But it just returns java.util.Random@addbf1. What am I doing wrong? And ignore int t for now.[/QUOTE] Shouldn't that be [cpp] System.out.println(rand.nextInt(6)); [/cpp] ?
[QUOTE=fewes;26355707]Shouldn't that be [cpp] System.out.println(rand.nextInt(6)); [/cpp] ?[/QUOTE] Indeed it is! Thank you sir! [editline]28th November 2010[/editline] I just need a way for it to stop printing out 0's.
[QUOTE=fewes;26354137]That's what's odd. I can't find anything wrong with the code at all. Here's the surrounding code: bool m_fStayPushed; // button stays pushed in until touched again? bool m_fRotating; // a rotating button? default is a sliding button. locksound_t m_ls; // door lock sounds byte m_bLockedSound; // ordinals from entity selection byte m_bLockedSentence; What's strange is that this isn't my code. It's Valve's default one.[/QUOTE] Well guess what fixed it. I did: [cpp] #include "buttons.h" #include "cbase.h" #include "triggers.h" [/cpp] instead of [cpp] #include "cbase.h" #include "triggers.h" #include "buttons.h" [/cpp] The fuck's up with that [editline]28th November 2010[/editline] Well, damn. It didn't fix anything. The compiler just ignored #include "buttons.h". Fuck. [editline]28th November 2010[/editline] However including a header file (locksounds.h) inside buttons.h did. I don't understand how the hell that works, but fine I guess.
Does anyone have any ideas as to how i could make the positioning look more realistic? [media]http://www.youtube.com/watch?v=VJzcsPSmIzA[/media] Id like it so that the trees are behind the player or in front depending on the position of both.
[QUOTE=Richy19;26359525]Does anyone have any ideas as to how i could make the positioning look more realistic? [media]http://www.youtube.com/watch?v=VJzcsPSmIzA[/media] Id like it so that the trees are behind the player or in front depending on the position of both.[/QUOTE] Change the z value based on if the player is below or above the tree sprite? Also what the hell are those sounds in that video, sounds like my sound card is flipping.
[QUOTE=fewes;26359963]Change the z value based on if the player is below or above the tree sprite? Also what the hell are those sounds in that video, sounds like my sound card is flipping.[/QUOTE] Yea its the screen recording software. Also im using SFML and as far as i know it doesnt have an option for Z
[QUOTE=Richy19;26360195]Yea its the screen recording software. Also im using SFML and as far as i know it doesnt have an option for Z[/QUOTE] you should code your own z-order indexing in that case(store all your sprites, sort them by z-order, draw.)
[QUOTE=ZeekyHBomb;25680020]The problem in your code is that 1) new[] will initialize stuff as random memory (you could use new int[treeint](); to init to 0) 2) the tree is accepted as long as [i]one[/i] tree does not collide with the current. [cpp]int distance(const sf::Vector2i &a, const sf::Vector2i &b) { const int dx = a.x - b.x, dy = a.y - b.y; return dx * dx + dy * dy; } //... const std::size_t treeint = sf::Randomizer::Random(15, 28); sf::Vector2i *trees = new sf::Vector2i[treeint]; for(std::size_t i = 0 ; i < treeint; i++ ) { init_tree: trees[i] = sf::Vector2i(sf::Randomizer::Random(0, 780), sf::Randomizer::Random(0, 620)); for(std::size_t z = 0; z < i; z++) { if(distance(trees[i], trees[z]) < 100 * 100) { goto init_tree; } } std::cout << trees[i].x << '\n' << trees[i].y << std::endl; }[/cpp][/QUOTE] ZeekyHBomb, a while back you wrote this for me to check whether the new position of a tree is too close to other trees, i am now trying to use the same thing to check if something is basically within the tree I have managed to get it working more or less bt i need to know how i change the distance of the objects i want it to check for
Line 18. But I think it'd be enough if you just sort by y (up/down).
Are there any good lightweight programs out there that will visualize your classes and their inheretance?
Managed to do the hole positioning stuff. Now to fix the collision :/ ive also added some stuff to see the problem much easier, il upload a video after dinner see if anyone on here can identify the problem [editline]28th November 2010[/editline] Made another video that hopefully shows the problem from a better perspective: [media]http://www.youtube.com/watch?v=Fx4ORoMppqw[/media] BTW removed the grass tile so you can see it better
Managed to get everything working. Here's the result. [media]http://www.youtube.com/watch?v=0Z6TNfN2zHs[/media] Yay!
[QUOTE=CommanderPT;26355760]Indeed it is! Thank you sir! [editline]28th November 2010[/editline] I just need a way for it to stop printing out 0's.[/QUOTE] AFAIK, you'll never get 6's with random.NextInt(6), so you could floor it and add 1, 0's would become 1's [editline]28th November 2010[/editline] [QUOTE=CommanderPT;26355760]Indeed it is! Thank you sir! [editline]28th November 2010[/editline] I just need a way for it to stop printing out 0's.[/QUOTE] AFAIK, you'll never get 6's with random.NextInt(6), so you could floor it and add 1, 0's would become 1's
Yey i fixed the collision detection
From my thread: [url]http://www.facepunch.com/threads/1032091-Variables-not-initialized-(Java)?p=26371072#post26371072[/url] [code]/** * @(#)Tuition.java * Tuition.java * Created by World Renowned Pro-Everything * @version 1.00 2010/11/22 */ import java.io.*; import javax.swing.JOptionPane; public class Tuition { public static void main(String[] args) { int hours; double fees, rate, tuition; //Call Methods displayWelcome(); hours = getHours(); rate = getRate(hours); tuition = calcTuition(hours, rate); fees = calcFees(tuition); displayTotal(tuition + fees); } //Welcome message to user public static void displayWelcome() { JOptionPane.showMessageDialog(null, "Welcome to the Student Fees calculator!",null,JOptionPane.INFORMATION_MESSAGE); } //User prompt for hours public static int getHours() { String strHours; int hours = 0; strHours = JOptionPane.showInputDialog(null, "Please enter the total number of hours"); try { hours = Integer.parseInt(strHours); } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null,"Please use numbers only"); } return hours; } //calculate hours public static double getRate(int hours) { double rate; if (hours <= 15) { rate = hours*44.50; } else if (hours >= 15) { rate = hours*50; } return rate; } // place public static double calcTuition(int hours, double rate) { double tuition; tuition =(hours)*(rate); return tuition; } //place public static double calcFees(double tuition) { double fees; fees = tuition*(0.08); return fees; } //place public static void displayTotal(double total) { double fees, tuition; total = (fees)+(tuition); JOptionPane.showMessageDialog(null,"Your total cost is" + total); } }[/code] So IDE says the variables rate, fees and tuition have not been initialized. I really don't know where to go from here, any help would be appreciated. Thanks!
[QUOTE=Richy19;26371268]Yey i fixed the collision detection[/QUOTE] Hey you mind sharing code if it's 2d? I can't get mine to work well without bugs.
[QUOTE=Dr. Fishtastic;26371628]From my thread: [url]http://www.facepunch.com/threads/1032091-Variables-not-initialized-(Java)?p=26371072#post26371072[/url] So IDE says the variables rate, fees and tuition have not been initialized. I really don't know where to go from here, any help would be appreciated. Thanks![/QUOTE] Initalize them. [code] int hours = geHours(); int rate = getRate(hours); int tuition = calcTuition(hours, rate); int fees = calcFees(tuition); [/code] Java is a strongly typed language, you have to specify the type of every variable when initalizing it.
[QUOTE=WTF Nuke;26371730]Hey you mind sharing code if it's 2d? I can't get mine to work well without bugs.[/QUOTE] [cpp]for(int i = 0 ; i < treeint; i++ ) { Tree.SetPosition(trees[i].x,trees[i].y ); if(sf::FloatRect( Warrior.getSolidRect() ).Intersects( Tree.getSolidRect() ) ) { intersects = true ; Warrior.SetPosition(warriorPos); } } if(!intersects) { warriorPos = Warrior.GetPosition(); Warrior.Move(Warrior.getDirection(0) * App.GetFrameTime(), Warrior.getDirection(1) * App.GetFrameTime() ); } Warrior.setDirection(0,0); Warrior.setDirection(0,1); intersects = false; [/cpp] Thats pretty much all the collision detection i use, note that this uses SFML so will only be valid if you implement those features or are using SFML
[QUOTE=Richy19;26372458][cpp]for(int i = 0 ; i < treeint; i++ ) { Tree.SetPosition(trees[i].x,trees[i].y ); if(sf::FloatRect( Warrior.getSolidRect() ).Intersects( Tree.getSolidRect() ) ) { intersects = true ; Warrior.SetPosition(warriorPos); } } if(!intersects) { warriorPos = Warrior.GetPosition(); Warrior.Move(Warrior.getDirection(0) * App.GetFrameTime(), Warrior.getDirection(1) * App.GetFrameTime() ); } Warrior.setDirection(0,0); Warrior.setDirection(0,1); intersects = false; [/cpp] Thats pretty much all the collision detection i use, note that this uses SFML so will only be valid if you implement those features or are using SFML[/QUOTE] Wait hold on what's sf::FloatRect.Interesects()?
[QUOTE=WTF Nuke;26372683]Wait hold on what's sf::FloatRect.Interesects()?[/QUOTE] It checks 2 Rects to see if they intersect, and if they do it returns true
[QUOTE=Richy19;26372731]It checks 2 Rects to see if they intersect, and if they do it returns true[/QUOTE] So basically bounding box? This makes it easier. But how do you check if it's to the left, right, top, bottom of warrior?
it doesnt, it just gets given 2 squares and if it intersects anywhere it returns true Il try and find the documentation page
Hi. I don't know a lot about C#, and I have no idea why this is happening. It seems that only when I send a position+look packet, I get some sort of exception about illegal access. I don't even know what that means, but i'm guessing it has something to with public/private. The console output looks like this [code] A new client has connected from 127.0.0.1:56113. ClientNetwork init'd ID: 1 Thread started! A Handshake packet is being made. A Login responce packet is being made. A prechunk (0,0) is being made. A chunk (0,0) is being made. A spawn position packet is being made. A position+look packet is being made. Unhandled Exception: System.UnauthorizedAccessException: Access to the requested resource is not authorized. at System.IO.MemoryStream.GetBuffer () [0x00000] in <filename unknown>:0 at craftmine2.PacketCreator.getBuffer () [0x0000b] in /home/me/Projects/craftmine/craftmine2/PacketCreator.cs:13 at craftmine2.ClientNetwork.parsePacket (craftmine2.PacketCreator create) [0x000cb] in /home/me/Projects/craftmine/craftmine2/ClientNetwork.cs:72 at craftmine2.ClientNetwork.Handle (System.Byte[] msg, Boolean direct) [0x00029] in /home/me/Projects/craftmine/craftmine2/ClientNetwork.cs:82 at craftmine2.ClientLogic.ListenForData () [0x00034] in /home/me/Projects/craftmine/craftmine2/ClientLogic.cs:31 [/code] and the function that it's crashing at is getBuffer, which looks like [code] public byte[] getBuffer(){ write.Flush(); byte[] buf = memstream.GetBuffer(); return buf; } [/code] In the console output, each time it says packet X is being made, this function is called. It only happens in the position+look packet, which incedentialy is the same packet that the client is crashing at. Could someone shed some light on what this exception means, and possibly why i'm getting it? Write is a binarywriter, and memstream is it's stream. Code for making a position+look packet. [code] public class pPosLook : Packet{ byte ID = 0x0D; string name = "position+look"; int x,y,z; public pPosLook (int xx, int yy, int zz){ Console.WriteLine("A {0} packet is being made.",name); x = xx; y = yy; z = zz; } public override byte[] build(){ PacketCreator create = new PacketCreator(); create.writeByte(ID); create.writeDouble(x); create.writeDouble(67); create.writeDouble(y); create.writeDouble(z); create.writeFloat(0); create.writeFloat(0); create.writeBool(true); return create.getBuffer(); } } [/code] And yes, this is threaded. By the way, this is for a custom minecraft server.
Thi is the documentation [url]http://www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.htm[/url] [editline]29th November 2010[/editline] [QUOTE=bobthe2lol;26372856] Unhandled Exception: System.UnauthorizedAccessException: Access to the requested resource is not authorized. [/QUOTE] Just a wild guess but could it need to be run as administrator? [editline]29th November 2010[/editline] [QUOTE=bobthe2lol;26372856] Unhandled Exception: System.UnauthorizedAccessException: Access to the requested resource is not authorized. [/QUOTE] Just a wild guess but could it need to be run as administrator?
[QUOTE=Richy19;26372864]Thi is the documentation [url]http://www.sfml-dev.org/documentation/2.0/classsf_1_1Rect.htm[/url] [editline]29th November 2010[/editline] Just a wild guess but could it need to be run as administrator? [editline]29th November 2010[/editline] Just a wild guess but could it need to be run as administrator?[/QUOTE] No how does YOUR program check? I mean, what's the point if finding out if it collides, you gotta know which way so as to restrict moving in that direction.
Ohh well basically when nothing is intersecting a vector warriorPos gets assigned the current position of warrior and then the warrior is moved. If when he moves he intersects the intersection boolean goes true and the warriors position gets set to its previous position in which it didnt intersect. Also it doesnt let you mmove in that frame
[QUOTE=Richy19;26372997]Ohh well basically when nothing is intersecting a vector warriorPos gets assigned the current position of warrior and then the warrior is moved. If when he moves he intersects the intersection boolean goes true and the warriors position gets set to its previous position in which it didnt intersect. Also it doesnt let you mmove in that frame[/QUOTE] But what if the player hits say left and up? And then he collides in the up direction, so he can't go anywhere.
yes if he collides while going in diagonal he would just stop
That sounds like a flaw to me.
Its not perfect but he doesnt get stuck inside the collision box :v:
Sorry, you need to Log In to post a reply to this thread.