• What do you need help with? V. 3.0
    4,884 replies, posted
[csharp] public void ReceiveStart(int port) { TcpListener Listener = new TcpListener(IPAddress.Any, port); while (true) { try { Listener.Start(); Socket Soc = Listener.AcceptSocket(); Stream s = new NetworkStream(Soc); byte[] b = new byte[100]; int k = Soc.Receive(b); for (int i = 0; i < k; i++) { Console.WriteLine(Convert.ToChar(b[i])); } } catch (Exception ex) { Console.WriteLine(ex); } } } [/csharp] Probably something stupid I missed.
[QUOTE=Fetret;33528537]Can someone help me with getting sound amplitude (sound energy) with FMOD? Basically I am trying to do beat detection. I understand how beat detection works/should work, but I can't seem to get the amplitude from FMOD. I feel like I am missing a huge point. I know how to get and work on the spectrum data, but I can't figure out how to use that as an average and instant value to do comparisons and detect beats.[/QUOTE] Take a few samples (at least a few wavelengths), square each sample and add them all together. This is for energy, not amplitude. They are, in fact, different. For example, a square wave contains more energy than a sine wave with equal amplitude.
[QUOTE=reevezy67;33536888][csharp] public void ReceiveStart(int port) { TcpListener Listener = new TcpListener(IPAddress.Any, port); while (true) { try { Listener.Start(); Socket Soc = Listener.AcceptSocket(); Stream s = new NetworkStream(Soc); byte[] b = new byte[100]; int k = Soc.Receive(b); for (int i = 0; i < k; i++) { Console.WriteLine(Convert.ToChar(b[i])); } } catch (Exception ex) { Console.WriteLine(ex); } } } [/csharp] Probably something stupid I missed.[/QUOTE] That returns void. I don't know how to create threads in C#, but in Java you create a new anonymous Thread class, like this: [csharp] Thread thread=new Thread(){ public void run(){ } } thread.start(); [/csharp]
[QUOTE=Map in a box;33537065]That returns void. I don't know how to create threads in C#, but in Java you create a new anonymous Thread class, like this: [csharp] Thread thread=new Thread(){ public void run(){ } } thread.start(); [/csharp][/QUOTE] Yeah, I managed to fix it with this. [csharp] t[i] = new Thread(new ThreadStart(delegate() { ReceiveStart(port); })); [/csharp]
In java, how would I get strings "1" and "b" from the input "1b"?
[QUOTE=Blueridge;33536410]Trying to learn love so I went on google and found [URL="http://www.headchant.com/2010/12/31/love2d-%E2%80%93-tutorial-part-2-pew-pew/"]this[/URL] tutorial. I don't know if it's outdated or not, but it was made last year so it can't be too old. And removing the semicolon produces the same error[/QUOTE] Replace "& lt;" with "<". It's an error on the webpage. Similarly, &gt; with >.
[QUOTE=ZeekyHBomb;33536248]Try gdb instead of valgrind.[/QUOTE] I get this [code][Thread debugging using libthread_db enabled] Using resolution: 800x600 Using OpenGL 2.1 Using GLEW 1.6.0 Using an Tungsten Graphics, Inc graphics card. Loading file: ./Data/PalmTree.png Loading file: ./Data/MenuBackground.png Loading file: ./Data/pedro.png Compiling shader : ./Data/vert.vert Compiling shader : ./Data/frag.frag Linking program Compiling shader : ./Data/vert.vert Compiling shader : ./Data/frag.frag Linking program Compiling shader : ./Data/vert.vert Compiling shader : ./Data/frag.frag Linking program [Inferior 1 (process 6643) exited with code 01] (gdb) [/code]
[QUOTE=reevezy67;33536798][csharp] public void StartListening() { int port = 8888; Thread[] t = new Thread[4]; for (int i = 0; i < 4; i++) { t[i] = new Thread(new ThreadStart(ReceiveStart(port))); port++; } } [/csharp] Gives me a "Method name expected." error on.. [csharp] t[i] = new Thread(new ThreadStart(ReceiveStart(port))); [/csharp][/QUOTE] That would be calling the method. When constructing a delegate you are supposed to pass the method. Also you want to use 'ParameterizedThreadStart' instead because you are passing a parameter. [csharp] t[i] = new Thread(new ParameterizedThreadStart(ReceiveStart)); t[i].Start(port); public void ReceiveStart(object obj) { int port = (int)obj; }[/csharp] [url]http://msdn.microsoft.com/en-us/library/6x4c42hc.aspx[/url]
[QUOTE=Richy19;33538665]I get this [code][Thread debugging using libthread_db enabled] Using resolution: 800x600 Using OpenGL 2.1 Using GLEW 1.6.0 Using an Tungsten Graphics, Inc graphics card. Loading file: ./Data/PalmTree.png Loading file: ./Data/MenuBackground.png Loading file: ./Data/pedro.png Compiling shader : ./Data/vert.vert Compiling shader : ./Data/frag.frag Linking program Compiling shader : ./Data/vert.vert Compiling shader : ./Data/frag.frag Linking program Compiling shader : ./Data/vert.vert Compiling shader : ./Data/frag.frag Linking program [Inferior 1 (process 6643) exited with code 01] (gdb) [/code][/QUOTE] According to that your program did not crash, but end with a return-code of 1.
[QUOTE=ZeekyHBomb;33538735]According to that your program did not crash, but end with a return-code of 1.[/QUOTE] But no where in my code do I return 1
[QUOTE=Richy19;33542581]But no where in my code do I return 1[/QUOTE] Show us your main.
Could be an exit(1) or something from within the library (though that's probably a bad idea actually). You could set a breakpoint after you create the shader program (or add more output to narrow it down) and step through each statement from there to see where precisely it stops executing.
[QUOTE=Richy19;33542581]But no where in my code do I return 1[/QUOTE] What libraries are you using? Occasionally some jackass will slip an exit(1) somewhere as an 'error handling mechanism'.
Is it possible to change the backcolor of a windows form while the program is running?
[QUOTE=reevezy67;33546144]Is it possible to change the backcolor of a windows form while the program is running?[/QUOTE] All the properties in the designer are actually a property in the class. So you can either do this.BackColor = color; if you are in the form class or you can do formobj.BackColor = color if you have a reference to the form.
[QUOTE=ZachPL;33528369]Hey guys, I am really getting annoyed with my python assignment and I really hope someone can help me out. Here is the fuction that I created for creating a random walk that should create a 2 circles with a line joining them each time in different directions. But this is what I am currently getting. Thanks I can really use any help :D[/QUOTE] Uhh, shouldn't [code]x2 = x1 + cos(angle) + 50 y2 = y1 + sin(angle) + 50[/code] be [code]x2 = x1 + cos(angle)*50 y2 = y1 + sin(angle)*50 [/code] ?
hierarchical database structure. That's just a way of using keys right? I can do that in MySQL right? all in the same table? Or is having 1 key point to another entry still a relational database? If I can do so in MySQL would I have another table where parents store a list of their children in the same field? like so [code] parentID|childrenIDs daddy001|daughter002,son003,bastard666 [/code] or would I do something like this [code] parentID|childrenID daddy001|daughter002 daddy001|son003 daddy001|bastard666 [/code]
[QUOTE=chimitos;33537973]In java, how would I get strings "1" and "b" from the input "1b"?[/QUOTE] I think what you are substring();
[QUOTE=ROBO_DONUT;33544734]What libraries are you using? Occasionally some jackass will slip an exit(1) somewhere as an 'error handling mechanism'.[/QUOTE] Just SFML [QUOTE=Jookia;33542675]Show us your main.[/QUOTE] [cpp]#include <SFML/Graphics.hpp> #include <iostream> int main() { sf::ContextSettings Settings; Settings.DepthBits = 24; // Request a 24 bits depth buffer Settings.StencilBits = 8; // Request a 8 bits stencil buffer Settings.AntialiasingLevel = 2; Settings.MajorVersion = 2; Settings.MinorVersion = 0; sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics",sf::Style::Default, Settings); sf::Texture tex; tex.LoadFromFile("ship.png"); sf::Sprite spr = sf::Sprite(tex); sf::Shader bloom; bloom.LoadFromFile("Bloom.fx"); bloom.SetParameter("amount", 0.6f); bloom.SetParameter("blurSize", 0.5f / 800); spr.Move(200,200); sf::RenderTexture bloomImage; bloomImage.Create(800,600); sf::Sprite bloomSprite = sf::Sprite(bloomImage.GetTexture()); while (App.IsOpened()) { sf::Event Event; while (App.PollEvent(Event)) if (Event.Type == sf::Event::Closed) App.Close(); App.Clear(); bloomImage.Clear(sf::Color(0.f,0.f,0.f,0.f)); bloomImage.Draw(spr, bloom); //NOTE TO SELF: ALWAYS SET SHADER PARAMETERS >AFTER< YOU USE THEM FOR DRAWING //Bloom.SetParameter("blurSize", 0.5f / Globals.GameHeight); bloom.SetParameter("horizontal", 0); bloomImage.Display(); App.Draw(bloomSprite, bloom); //Bloom.SetParameter("blurSize", 0.5f / Globals.GameHeight); bloom.SetParameter("horizontal", 1); App.Display(); } return 0; }[/cpp]
Try setting a breakpoint at exit and _exit (b exit and b _exit). When it halts, do bt to see the call stack. I'll be good to have a debug-build so the call stack is completely in tact.
In SFML, when you want to draw something, you use the function app.Draw(something), where app is the name of whatever your RenderWindow is called. I want to have a Class, that has a function, which draws itself. So if my Class is called "car", then I want to use the funtion Car.Draw(); to draw it. I have tried this, but it does not work: [code] class Test { public: Test(); ~Test(); void Draw(sf::RenderWindow); void setColor(sf::Color, sf::Color); void setPosition(int, int); void setSize(int, int); private: int xPosition; int yPosition; int height; int length; sf::Color backgroundColor; sf::Color foregroundColor; }; void Test::Draw(sf::RenderWindow window) { window.Draw(sf::Shape::Rectangle(100, 100, 200, 200, sf::Color(100, 100, 100))); } [/code] The Code does not do much yet. I want to get the drawing to work first of all. Any help would be appreciated.
[QUOTE=xxxkiller;33550729]In SFML, when you want to draw something, you use the function app.Draw(something), where app is the name of whatever your RenderWindow is called. I want to have a Class, that has a function, which draws itself. So if my Class is called "car", then I want to use the funtion Car.Draw(); to draw it. I have tried this, but it does not work: [code] class Test { public: Test(); ~Test(); void Draw(sf::RenderWindow); void setColor(sf::Color, sf::Color); void setPosition(int, int); void setSize(int, int); private: int xPosition; int yPosition; int height; int length; sf::Color backgroundColor; sf::Color foregroundColor; }; void Test::Draw(sf::RenderWindow window) { window.Draw(sf::Shape::Rectangle(100, 100, 200, 200, sf::Color(100, 100, 100))); } [/code] The Code does not do much yet. I want to get the drawing to work first of all. Any help would be appreciated.[/QUOTE] "window" in your Draw() function is a copy of the sf::RenderWindow you pass it, not the original sf::RenderWindow object. To fix that, simply pass a reference instead: [cpp]void Test::Draw(sf::RenderWindow &window)[/cpp] [editline]3rd December 2011[/editline] Also, I'd recommend passing sf::RenderTarget instead of sf::RenderWindow, just means you can do stuff like Draw(someRenderImage) as well as Draw(myWindow).
Thank you! It worked flawlessly on the first try! May I ask what the difference between RenderWindow and RenderTarget is?
[QUOTE=xxxkiller;33550832]Thank you! It worked flawlessly on the first try! May I ask what the difference between RenderWindow and RenderTarget is?[/QUOTE] Glad to hear you got it working! RenderTarget serves as the base class for things like RenderWindow and RenderImage. It provides the .Draw() function which the aforementioned classes can override to perform more specific operations. For example, RenderWindow draws the given Drawable to its window context, while RenderImage draws it to a texture stored in memory. The reason I recommend you use that is so that if you ever need to draw to something that isn't a window (like a texture), you can!
Good to know. Thank you for the quick responses!
[QUOTE=xxxkiller;33551049]Good to know. Thank you for the quick responses![/QUOTE] Glad to help. It's not like I have anything better to be doing :D
Alright, getting back to programming since I'm on vacation, 5 minutes into my new project and I already run into a problem. I'm trying to call App.Draw() from within the Player class I created, but instead of it drawing the sprite itself it just draws a white pixel. Here's my code: main.cpp [cpp] /////////////// // Headers /// ///////////// #include <SFML/Graphics.hpp> #include <iostream> #include "player.h" int main() { sf::RenderWindow App(sf::VideoMode(1280, 720, 32), "Bullet Fusion"); App.SetFramerateLimit(60); Player P1 = Player(1280/2, 720-64); // Start game loop while (App.IsOpened()) { // Process events sf::Event Event; while (App.PollEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); } // Get elapsed time float ElapsedTime = App.GetFrameTime(); // Clear screen App.Clear(); // Update the player P1.tick(App); // Display window contents on screen App.Display(); } return EXIT_SUCCESS; } [/cpp] player.cpp [cpp] /////////////// // Headers /// ///////////// #include <SFML/Graphics.hpp> #include <iostream> #include "player.h" ///////////////////////// // Player Ship Class /// /////////////////////// Player::Player(int x, int y) { ////////////////////////// // Variable assigment /// //////////////////////// ~cool variables~ /////////////////////////////////// // Load the ship's image files /// ///////////////////////////////// /// Ship, regular, frame 1 //sf::Image img_pship_r1; img_pship_r1.LoadFromFile("data/gfx/ship/pship_r1.png"); /// Ship, regular, frame 2 //sf::Image img_pship_r2; img_pship_r2.LoadFromFile("data/gfx/ship/pship_r2.png"); ////////////////////////////// // Create the ship sprite /// //////////////////////////// /// Player Ship Sprite sf::Sprite spr_pship(img_pship_r1); /// Set the scale and position of the ship spr_pship.SetPosition(x, y); spr_pship.SetScale(2.0f, 2.0f); } Player::~Player () { // I'm useless, go away. } void Player::tick(sf::RenderWindow &App) { ////////////////////// // Player Movement // //////////////////// ~cool movement code~ // Update the ship's position spr_pship.SetPosition(x, y); ///////////////////// // Player Drawing // /////////////////// std::cout << "Drawing ship inside tick() at: "; std::cout << x; std::cout << ", "; std::cout << y; std::cout << "\n"; App.Draw(spr_pship); } [/cpp] Can anyone see what's wrong with my code? I can't see anything that I'm doing wrong, but that's what happens every time so I'll just assume I'm missing it :v:
[QUOTE=Samuka97;33551427]Alright, getting back to programming since I'm on vacation, 5 minutes into my new project and I already run into a problem. I'm trying to call App.Draw() from within the Player class I created, but instead of it drawing the sprite itself it just draws a white pixel. Here's my code: main.cpp [cpp] img_pship_r1.LoadFromFile("data/gfx/ship/pship_r1.png"); [/cpp] Can anyone see what's wrong with my code? I can't see anything that I'm doing wrong, but that's what happens every time so I'll just assume I'm missing it :v:[/QUOTE] It can't find the image file is my guess. I haven't used SFML but looking at its docs it seems that LoadFromFile doesn't throw an exception if the file is not found, but rather it returns false if it fails. Check its return value.
[QUOTE=ThePuska;33551621]It can't find the image file is my guess. I haven't used SFML but looking at its docs it seems that LoadFromFile doesn't throw an exception if the file is not found, but rather it returns false if it fails. Check its return value.[/QUOTE] It's returning true, that means it's loading. But I came back to the thread just now to post that I found out what was wrong. Apparently, when you assign an sf::Image to a sf::Sprite, the Sprite doesn't actually contain the image, so it was just returning a blank image when I tried to draw it. To avoid that, I simply had to make the sf::Image a part of the Player class to avoid it from being deleted after the creation function was done. Silly me :v:
why does rand always start with 41 in c++ :v: [code]#include<iostream> #include <stdlib.h> using namespace std; int main() { int const cap = 10; int array1[cap]; for(int i = 0; i < 10; i++) { array1[i] = rand()%100; cout<<array1[i]<<", "; } cin.get();// KEEP CMD OPEN FOR MS VISUAL EXPRESS BECAUSE THERE RETARDED, and is also better than system("pause"). return 0; } [/code] [code]41, 67, 34, 0, 69, 24, 78, 58, 62, 64[/code]
Sorry, you need to Log In to post a reply to this thread.