• What do you need help with? V. 3.0
    4,884 replies, posted
[QUOTE=ruarai;31420744][lua] function isinside(id,x,y,xx,yy) ox, oy, xo, yo = objects[id].shape:getPoints() if x == ox or ox > x then if y == oy or oy > y then if xo < xx or xo == xx then if yo < yy or yo == yy then return true end end end end return false end [/lua] Excuse the lazy if statements, this was just a bit of draft code, but i can't get it to work. It's supposed to tell if one square xo,yo,ox,oy is inside another one x, y, yy, xx. But it just wont work. I'm really confused. LOVE2d code, btw[/QUOTE] First of all, expressions like "x == ox or ox > x" are equivalent to "ox >= x". Second, use local variables where ever you don't need global scope. Finally, the Love2D documentation says that shape:getPoints returns vertex coordinates for a polygon. You should have more than four values unless your items are all lines. For squares, it would have to be eight items. You probably want to be able to handle every type of polygon to avoid bugs, so you'd do something like this: [lua] function isinside(id, xmin, ymin, xmax, ymax) local v = {objects[id].shape:getPoints()} for i=0, #v/2 do local x = v[i*2] local y = v[i*2+1] if (x < xmin or y < ymin or x > xmax or y > ymax) then return false end end return true end [/lua] Note that this [i]only tests vertexes[/i]. Intersections can occur without any vertex being contained within the bounding box. It's left up to you to determine whether this is an acceptable approximation.
Okay so I'm a fucking idiot with programming. I'm using Blitz3D right now and am trying to make a simple text based game. I need multiple "If place$ = *insert place here*" instances but every time I put more than one and try to run it, it tells me "Expecting EndIf" even when I have EndIf's in the right position. This is the code: [code]Graphics 800,600 AppTitle "YOU CAN'T WIN" name$ = Input("Welcome to YOU CAN'T WIN. Please enter your name. ") If name$ = "King Alejandro" Print "YOU THOUGHT YOU COULD BE THE CHAMPION. YOU WERE WRONG. GAME OVER." WaitKey() End EndIf Print "Welcome to the game, " + name$ Delay 1000 Print "The rules are simple. You cannot win." Delay 1000 place$ = Input("Where do you want to go? ") If place$ = "Home" Print "You go home and open the door. Suddenly, the floor rips open and a demon swallows you whole. Delay 1500 Print "Press any key to exit the game. To restart, run the executable again!" WaitKey() EndIf If place$ = "Hell" Print "You went to Hell. Why would you do this? GAME OVER." Delay 1000 Print Print "Press any key to exit the game. To restart, run the executable again!" WaitKey() EndIf EndIf[/code] [editline]30th July 2011[/editline] How do I go about putting multiple If's?
[QUOTE=FFStudios;31424413]Okay so I'm a fucking idiot with programming. I'm using Blitz3D right now and am trying to make a simple text based game. I need multiple "If place$ = *insert place here*" instances but every time I put more than one and try to run it, it tells me "Expecting EndIf" even when I have EndIf's in the right position. This is the code: [code]Graphics 800,600 AppTitle "YOU CAN'T WIN" name$ = Input("Welcome to YOU CAN'T WIN. Please enter your name. ") If name$ = "King Alejandro" Print "YOU THOUGHT YOU COULD BE THE CHAMPION. YOU WERE WRONG. GAME OVER." WaitKey() End EndIf Print "Welcome to the game, " + name$ Delay 1000 Print "The rules are simple. You cannot win." Delay 1000 place$ = Input("Where do you want to go? ") If place$ = "Home" Print "You go home and open the door. Suddenly, the floor rips open and a demon swallows you whole. Delay 1500 Print "Press any key to exit the game. To restart, run the executable again!" WaitKey() EndIf If place$ = "Hell" Print "You went to Hell. Why would you do this? GAME OVER." Delay 1000 Print Print "Press any key to exit the game. To restart, run the executable again!" WaitKey() EndIf EndIf[/code] [editline]30th July 2011[/editline] How do I go about putting multiple If's?[/QUOTE] like so [code] .model small .stack 100h .386 .data info db 30 dup (0) right db ' wrong db nomscdex db .code mov ax, @data ; mov ds,ax mov es,ax lea edx, nomscdex xor ebx,ebx mov eax, 1500h ; int 2fh test ebx,ebx jz exit mov edi,10h nextloop: mov ecx,edi mov ax, 150bh ; int 2fh test ax,ax ; jz continiue mov ax, 440dh mov dx, offset info mov bl,5 mov ch,8 mov cl,66h int 21h mov eax, dword ptr [info+2] cmp eax, 0ffb7f724h; ; jnz continiue lea edx, right jmp exit continiue: dec edi jnz nextloop lea edx, wrong exit: mov ah, 9h int 21h mov ax,4c00h ; terminate! int 21h end [/code]
oh yeah makes a ton of sense lmao i figured it out myself btw
Does anyone know of any good tutorials on modifying binary data using C++ (e.g. removing bytes from a file... replacing bytes, etc?)? I've been Googling shit for the past 20 minutes but I can't find anything that's really understandable. =/
std::fstream?
Can anyone point me in the right direction for procedural cave generation, 2d. I've tried just taking 2d perlin noise and using values below -0.5 but it's not working well...not well at all.
I'm having a HTTP problem . I send a server the following request [code] GET //res/img/icons/facebook.jpg HTTP/1.1 Host: demotywatory.pl [/code] but I get the following response [code] HTTP/1.1 200 OK Server: nginx/0.8.53 Date: Sat, 30 Jul 2011 11:40:19 GMT Content-Type: image/jpeg Content-Length: 1085 Last-Modified: Fri, 29 Oct 2010 14:59:08 GMT Connection: keep-alive Keep-Alive: timeout=60 Expires: Tue, 09 Aug 2011 11:40:19 GMT Cache-Control: max-age=864000 Accept-Ranges: bytes *&#283;*Ó [/code] it gives me *&#283;*Ó at the end for every website I try. this doesn't happen to .js or .css files I guess because they are small
I need help with using SFML in Code::Blocks, I have it all set up correctly, and I'm using the tutorial to try and draw a basic window but it's not showing Here's the code [quote] #include <SFML/Window.hpp> int main() { // Create the main window sf::Window App(sf::VideoMode(800, 600, 32), "SFML Window"); // Start main loop bool Running = true; while (Running) { App.Display(); } return EXIT_SUCCESS; } [/quote] I know SFML is set up correctly as the code in this tutorial works perfectly: [url]http://www.sfml-dev.org/tutorials/1.6/start-cb.php[/url] When I run the application I just get the console window: [url]http://dl.dropbox.com/u/3901038/FP/sfml/SFM2L.JPG[/url] I've tried compiling in Debug and Release (using their respective dependencies)
[QUOTE=cdlink14;31430471]I need help with using SFML in Code::Blocks, I have it all set up correctly, and I'm using the tutorial to try and draw a basic window but it's not showing Here's the code I know SFML is set up correctly as the code in this tutorial works perfectly: [url]http://www.sfml-dev.org/tutorials/1.6/start-cb.php[/url] When I run the application I just get the console window: [url]http://dl.dropbox.com/u/3901038/FP/sfml/SFM2L.JPG[/url] I've tried compiling in Debug and Release (using their respective dependencies)[/QUOTE] [cpp] int main() { // Create the main rendering window sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics"); // Start game loop while (App.IsOpened()) { // Process events sf::Event Event; while (App.GetEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); } // Clear the screen (fill it with black color) App.Clear(); // Display window contents on screen App.Display(); } return EXIT_SUCCESS; }[/cpp] You dont want to use a bool in your main loop
[QUOTE=Richy19;31430596] int main(){ // Create the main rendering window sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics"); // Start game loop while (App.IsOpened()) { // Process events sf::Event Event; while (App.GetEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); } // Clear the screen (fill it with black color) App.Clear(); // Display window contents on screen App.Display(); } return EXIT_SUCCESS;} You dont want to use a bool in your main loop[/QUOTE] It's fine to use a "running" flag, it enables you to have more control than just relying on the window being open. Just don't forget to set it to false at some point in the code :v: Edit: What the hell, this new reply box breaks code tags
Also forgot to mention it happens in Code::Blocks and VS2008. I've set them up per the respective tutorials. [editline]30th July 2011[/editline] [QUOTE=Richy19;31430596][cpp] int main() { // Create the main rendering window sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics"); // Start game loop while (App.IsOpened()) { // Process events sf::Event Event; while (App.GetEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); } // Clear the screen (fill it with black color) App.Clear(); // Display window contents on screen App.Display(); } return EXIT_SUCCESS; }[/cpp] You dont want to use a bool in your main loop[/QUOTE] Tried running your code, and still nothing comes up.
I remember someone having the exact same problem, and it was something among the lines of not getting past the first instruction for some reason; my memory escapes me though. Start it through the debugger and tell it to halt right at the start of the program, then step through each instruction to see where exactly it hangs.
Well when I set it to debug it doesn't seem to reach any breakpoints( it doesn't even reach "int main()" ), which leads me to believe this is an error with an header file... Any help on how to go about finding/fixing it?
Wrong thread!
You can try pausing the program; there should be a button while debugging for this.
[QUOTE=marcin1337;31427705]I'm having a HTTP problem . I send a server the following request [code] GET //res/img/icons/facebook.jpg HTTP/1.1 Host: demotywatory.pl [/code] but I get the following response [code] HTTP/1.1 200 OK Server: nginx/0.8.53 Date: Sat, 30 Jul 2011 11:40:19 GMT Content-Type: image/jpeg Content-Length: 1085 Last-Modified: Fri, 29 Oct 2010 14:59:08 GMT Connection: keep-alive Keep-Alive: timeout=60 Expires: Tue, 09 Aug 2011 11:40:19 GMT Cache-Control: max-age=864000 Accept-Ranges: bytes *&#283;*Ó [/code] it gives me *&#283;*Ó at the end for every website I try. this doesn't happen to .js or .css files I guess because they are small[/QUOTE] Images aren't plaintext. Right after the \n\n at the end of the headers there is binary data which you are trying to read as ascii text.
I just installed ubuntu and am trying to compile some stuff from windows but one of the things it requires is glew I got the glew stuff from synaptic but it only seems to have included the static files, do i need to download a different package for the dynamic ones? Im using -lglew32 to link to it
[QUOTE=cdlink14;31430471]I need help with using SFML in Code::Blocks, I have it all set up correctly, and I'm using the tutorial to try and draw a basic window but it's not showing Here's the code I know SFML is set up correctly as the code in this tutorial works perfectly: [url]http://www.sfml-dev.org/tutorials/1.6/start-cb.php[/url] When I run the application I just get the console window: [url]http://dl.dropbox.com/u/3901038/FP/sfml/SFM2L.JPG[/url] I've tried compiling in Debug and Release (using their respective dependencies)[/QUOTE] Just got it working. I compiled SFML 2.0 myself using CMake and nmake.
[QUOTE=thf;31447001]It seems like it's an issue with AMD graphics drivers newer than 10.10 from what I've read. I just downgraded my drivers to try if it works. [editline]1:11[/editline] Nope, didn't work at all.[/QUOTE] It is true about the AMD drivers. Just move on to SFML 2.0
[QUOTE=AtomiCasd;31447833]It is true about the AMD drivers. Just move on to SFML 2.0[/QUOTE] Just did, it works perfectly :v:
[QUOTE=dill333;31413031]RiceWarrior, It's called operator overloading. When you overload the << operator, you need to pass it the stream it is using, along with whatever it is being operated on. So with your's, it is operating on a Point object. So when you use the operator with the point object, like the code "cout << john << endl;" does, then it uses the overloaded operator function to determine what to do with it. So in your case, it just prints out the X, Y, and Z of that point. [URL="http://www.cprogramming.com/tutorial/operator_overloading.html"]This[/URL] might help you out more.[/QUOTE] So from what I understand an overloaded operator/function is just a way to make an operator or function act differently depending on the input or parameters? Overloading a function is pretty simple but the syntax for overloading an operator still confuses me to no end. I'm going to look up some more videos and read up on it more. I can never keep going on with tutorials unless I understand concepts like this.
I have an XNA related question- What is the best way to have a view? So the screen scrolls about the room following the player or w/e. At the moment I have a vector2 with the room coordinates and when I'm drawing anything in the game I offset the drawing position by the coordinates of the view, but it there a better way of doing it?
Could anyone help me with some answers to some segmentation faults in my program? It is for an assignment with the details in the image below. Working with C in the Unix environment, etc. I am using a linked list to hold all the designated signals (in order) and every time the program reads T, it checks the head of the list to match the current time S then increments S, then prints out something. It also checks if S is past E so it won't bother adding anything to the list (hopefully). Usually after awhile I get very skeptical of what I write even after reviewing it. I appreciate any help. Basically it is mimicking a clock. [t]http://i62.photobucket.com/albums/h89/Veris_Zaos/project.png[/t] [code]#include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> //Assignment 3 //create link list struct listNode{ int data; //store information struct listNode *nextPtr; //listNode pointer }; //end structure listNode typedef struct listNode ListNode; //synonym for struct listNode typedef ListNode *ListNodePtr; //synonym for Listnode* int main (){ ListNodePtr *sPtr = NULL; //Initially there are no nodes ListNodePtr tempPtr; //create temporary node pointer ListNodePtr newPtr; //pointer to new node ListNodePtr previousPtr; //pointer to previous node in list ListNodePtr currentPtr; //pointer to current node in list newPtr = malloc(sizeof(ListNode)); //create new node char string[256]; //string pointer char *tokenPtr; //create character pointer int S; //sets the current time to S <int> int Si;//Initial Time to print out later int E; //schedules a signal to occur at time E <int> FILE *file; if (file = fopen("clock.txt", "r") == NULL){//checks for file error perror("Cannot Open File\n"); } else { while (!feof(file)){ //while file still has lines fscanf(file, "%s", string); //read line into string tokenPtr = strtok(string , " "); //begin tokenizing string while (tokenPtr != NULL){ //while there are still tokens left if (tokenPtr = "S"){ //S sets the current time S = strtok(NULL, " "); //get next token Si = S; //Keep initial time for reference } else if (tokenPtr = "E"){ //E schedules a singal E = strtok(NULL, " ");//get next token if (E > S){ //Checks if E schedule is set after timer is passed. printf("Time is Past E = %d/n", E); } else{ if(newPtr != NULL){ newPtr->data = E; //place value in node newPtr->nextPtr = NULL; //node does not link to another node previousPtr = NULL; //set previous to NULL currentPtr = *sPtr; //set current to starting pointer while (currentPtr != NULL && E > currentPtr->data){ //loop to find correct location in list previousPtr = currentPtr; //move to ... currentPtr = currentPtr->nextPtr; // next node } if(previousPtr == NULL){ //insert new node at beginning of list newPtr->nextPtr = *sPtr; *sPtr = newPtr; } else {//insert new node between previousptr and currentptr previousPtr->nextPtr = newPtr; newPtr->nextPtr = currentPtr; } } else{ printf("No memory availible\n"); } } } else if (tokenPtr = "T"){ if (S == (*sPtr)->data){ printf("Signal at S = %d/n", S); tempPtr = *sPtr; //hold onto node being removed *sPtr = (*sPtr)->nextPtr; //de-thread the node free(tempPtr); //free the de-threaded node } else{} S++; } else if (tokenPtr = "P"){ printf("Current time = %d\n", S); } else if (tokenPtr < 0){ perror("Error\n"); EXIT_FAILURE; } } fclose(file); //close opened file } } return 0; //Success } [/code] The file to read from is in this format. [quote]S 10 T T E 9 T P T E 1 P [/quote] Just to say that this is a first time for C and Unix for me. I have used C++ before, but then things took a turn for Java (not sure why the University decided the whole shift). So far I think I got it down, but this segmentation error is keeping me at wits end. I googled some segmentation error tips but no good results. If some parts sound bookish, they probably are, because I got some C/C++ books to help me out.
[code]else if (tokenPtr = "E"){ //E schedules a singal[/code] Spot two things that are wrong. (Hint: the first one is that you're assigning, second one is that you don't compare strings like that in C)
I don't think anyone is going to be able to read that. You shouldn't need more than like 3/4 levels of indentation. Break things into sensible subroutines. First problem I'm seeing is that your usage of fscanf is wrong. fscanf("%s") will read the first whitespace delimited [i]word[/i], not the first [i]line[/i]. If you're using GCC, compile with the "-g" flag to generate debug information and run your program with "gdb <program>", then type "set args <args>" and "run". When it segfaults, type "backtrace" or "bt".
[cpp]ListNodePtr *sPtr = NULL;[/cpp] In addition to the other issues pointed out, sPtr is a pointer to a pointer which you set to NULL. Throughout the program you then dereference this without ever setting it to point to anything else. Dereferencing NULL will cause a segfault. Perhaps you just meant ListNodePtr sPtr;, though I'm still not all that clear on what the code is supposed to do. Additionally in a number of places you assign the value returned by strtok to an integer. strtok returns a character array (string). If you want the integer value corresponding to the string you need to parse it first, which can be achieved with sscanf or atoi I believe.
Thanks for the help. Sorry if I wasn't clear on what the code was supposed to do, bean_xp. It is supposed to mimic a clock by taking specific commands from a text file. The format of the file is on the bottom of my first post, which I edited to use "," as the delimiter instead of " ". File format is up to us, the instructor just wants it to work properly. At the moment, I have hopefully fixed some of the errors you all have spotted. I believe I have boiled down the bugs down to what is below: warning: comparison between pointer and integer For these lines: [quote] 41: if (tokenPtr == 'S') 45: else if (tokenPtr == 'E') 75: else if (tokenPtr == 'T') else if (tokenPtr == 'P') [/quote] It still compiles and no longer gives a segmentation faults when run, but now it blanks out the command prompt so my guess is that the program crashes when it hits the comparisons. I know I am screwing up badly and it probably is something simple.
Strings in C, such as tokenPtr, are pointers to arrays of characters. When you single-quote a character, it produces the [i]integer ASCII code[/i] for that character. You are comparing the [i]address[/i] of an array to the [i]ASCII value[/i] of a character. The hint I'll give is that strings are complex values which can't be directly compared in a single operation. As with most non-trivial common tasks, there should be a function to help you out.
[URL]http://www.cplusplus.com/reference/clibrary/cstring/strcmp/[/URL]
Sorry, you need to Log In to post a reply to this thread.