• What Do You Need Help With? V6
    7,544 replies, posted
It's because the line of [php]$queryResult = @mysqli_query($DBConnect, $IDString);[/php] $queryResult here, is not a string containing the customer number. Instead, it's a mysqli_result object. (Say, an organised array that's similiar to a mysql table with the result fields) Because later on you try to paste the value directly into a string, it tries to convert it to a string, and fails. I'm not too famliar with mysqli, but I think you could just do: [php] $row = mysqli_fetch_array($queryResult); echo "...customer number is ". $row["customernumber"]. " which ..."; [/php] This method returns a *readable* version of the array, so that you can access the fields within. In this case, customernumber. Edit: By the way, it actually returns just one row, so to access multiple rows (not needed in this example, but just for reference) you'd need to do this: [php] while($row = mysqli_fetch_array($queryResult) { echo $row["customernumber"]; } [/php] It loops through all the rows, so you can manipulate/output them.
[QUOTE=ThePuska;42303371]Assuming your camera is already on the sphere's surface (i.e. you just want to start circling the target point from your current coordinates). You [I]could[/I] just move along the current tangent surface. [code]// sphere_pos is the center of the sphere // camera_pos is the position of the camera // camera_up is the up direction of the camera // move_x is longitudal movement distance, move_y is latitudal vec3 delta = sphere_pos - camera_pos; // "longitudal" direction vec3 dx = vec3::norm(vec3::cross(delta, camera_up)); // "latitudal" direction vec3 dy = vec3::norm(vec3::cross(dx, delta)); camera_pos += move_x * dx + move_y * dy;[/code] The catch is that if move_x and move_y are not small, it'll quickly spiral outwards instead of truly circling.[/QUOTE] I guess I'll ask again, Is there a way of doing this that will work without it spiraling outwards? Using Lerp isn't a very good solution. [code] #include "PolyMouseOrbit.h" PolyMouseOrbit::PolyMouseOrbit(Core *_core, Camera *_camera, SceneEntity *_entity){ core = _core; camera = _camera; entity = _entity; sensitivity = 1; core->getInput()->addEventListener(this,InputEvent::EVENT_MOUSEMOVE); mouseVector = Vector2(0,0); distance = GetDistanceFromVectors(camera->position,entity->position); lerpTimer = new Timer(true,100/60); lerpTimer->addEventListener(this, Timer::EVENT_TRIGGER); } PolyMouseOrbit::~PolyMouseOrbit(void){ } void PolyMouseOrbit::handleEvent(Event *e){ if(e->getDispatcher()==core->getInput()){ InputEvent *inputEvent = (InputEvent*)e; if(e->getEventCode()==InputEvent::EVENT_MOUSEMOVE){ Vector2 mouseAxis = Vector2(0,0); if(mouseVector != Vector2(0,0)){ mouseAxis.x = (inputEvent->mousePosition.x - mouseVector.x)/14 * sensitivity; mouseAxis.y = (inputEvent->mousePosition.y - mouseVector.y)/14 * sensitivity; } mouseVector = inputEvent->mousePosition; Vector3 delta = entity->position - camera->position; Vector3 dx = delta; dx = dx.crossProduct(GetUpwardVector(camera->rotation)); dx.Normalize(); Vector3 dy = delta; dy = dy.crossProduct(dx); dy.Normalize(); camera->position -= (dx*mouseAxis.x) + (dy*mouseAxis.y); Quaternion quat = camera->getRotationQuat(); entity->setRotationQuat(quat.w,quat.x,quat.y,quat.z); } } if(e->getDispatcher()==lerpTimer && e->getEventCode() == Timer::EVENT_TRIGGER){ LerpUpdate(); } } void PolyMouseOrbit::LerpUpdate(){ if(distance < GetDistanceFromVectors(camera->position,entity->position)) { camera->position = Lerp(camera->position,entity->position,0.02f); } camera->lookAt(entity->position); } Vector3 PolyMouseOrbit::GetUpwardVector(Rotation rotation){ return Vector3( cos(rotation.yaw)*sin(rotation.pitch)*sin(rotation.roll) - sin(rotation.yaw)*cos(rotation.roll), sin(rotation.yaw)*sin(rotation.pitch)*sin(rotation.roll) + cos(rotation.yaw)*cos(rotation.roll), cos(rotation.pitch)*sin(rotation.roll)); } double PolyMouseOrbit::GetDistanceFromVectors(Vector3 v1, Vector3 v2){ Vector3 vecDist = Vector3( v1.x - v2.x, v1.y - v2.y, v1.z - v2.z ); return double( sqrt(pow(vecDist.x, 2) + pow(vecDist.y,2) + pow(vecDist.z,2))); } Vector3 PolyMouseOrbit::Lerp(Vector3 start, Vector3 end, float percent) { return Vector3( start.x + end.x - start.x * percent, start.y + end.y - start.y * percent, start.z + end.z - start.z * percent); } [/code]
[QUOTE=eternalflamez;42323473]It's because the line of [php]$queryResult = @mysqli_query($DBConnect, $IDString);[/php] $queryResult here, is not a string containing the customer number. Instead, it's a mysqli_result object. (Say, an organised array that's similiar to a mysql table with the result fields) Because later on you try to paste the value directly into a string, it tries to convert it to a string, and fails. I'm not too famliar with mysqli, but I think you could just do: [php] $row = mysqli_fetch_array($queryResult); echo "...customer number is ". $row["customernumber"]. " which ..."; [/php] This method returns a *readable* version of the array, so that you can access the fields within. In this case, customernumber. Edit: By the way, it actually returns just one row, so to access multiple rows (not needed in this example, but just for reference) you'd need to do this: [php] while($row = mysqli_fetch_array($queryResult) { echo $row["customernumber"]; } [/php] It loops through all the rows, so you can manipulate/output them.[/QUOTE] YOU'RE A LEGEND!
Also, C++ seems to be the language of choice on Facepunch at the moment, it was C# a couple of months ago IIRC. [editline]27th September 2013[/editline] Merge pirate.
[QUOTE=Arxae;42320061]Trying to get some shaders to work. Using SFML.NETn but all i'm getting is a black square. My testsprite is just the 2x2 cube from tetris (black and white) So, i initialize my shader stuff on the C# end like this (don't mind the variable names, just test stuff): [code] Texture texture = new Texture("media/block.png"); Sprite _sprite = new Sprite(texture); Shader shader = new Shader( "media/basic.vert", "media/basic.frag" ); shader.SetParameter( "texture", texture ); RenderStates states = new RenderStates( shader ); [/code][/QUOTE] Does texture (the variable) still exist when you use the shader for drawing? I might be completely wrong, but SFML.net requires the csfml libraries present, right? That might indicate, that SFML.net is not a re-implementation in C# (or another .NET language), but just bindings to the C(++?) version. And that could mean, that the shader does not keep the texture internally and the memory will be reclaimed by the garbage collector. [QUOTE=RoflKawpter;42320390]... I guess what I'm asking is: Is there any resources I can look at that will help me decide how to split up my classes? Is there any "decent" source code I can look at that someone has released that has used the Slick2D engine as a base? Thanks :)[/QUOTE] In general you just do what you would normally do: each separate component gets its own class. There is also no one single right way to do things. If it works, it works. I don't see any glaring issues with the code you posted, although I am also not familiar with Slick2D. Just some minor nitpicks, like [code]if("true".equals(value)) { blocked[xAxis][yAxis] = true; }[/code] Can just be [code]blocked[xAxis][yAxis] = "true".equals(value);[/code] Of course it's slightly different behavior, but since you know each entry in blocked is false to begin with, setting it to false again does no harm. The if-else if-chain in update() looks ugly and repetitive. Look if you can perhaps get an array of all pressed keys from Slick2D and switch over them. Instead of separate variables for the animations, consider having an enum specifying the direction and using that to index an array of directions [code]enum Direction { Up, Down, Left, Right, Max } Animation[] facingSprites = new Animation[Direction.Max]; //... //in init() facingSprites[Direction.Up] = new Animation(up, duration, false); facingSprites[Direction.Down] = new Animation(down, duration, false); //... //in update() Direction direction; swtich(pressedKeys) { case Input.KEY_UP: direction = Direction.Up; break; case Input.KEY_DOWN: direction = Direction.Down; break; //... } if(direction) { sprite = facingSprites[direction]; sprite.update(delta); }[/code] And in case you run into design errors, refactor. Trial and error. Practice makes perfect. [QUOTE=SteelSliver;42322023][CODE]#include<headers.h> SDL_Surface *load_image(std::string filename) { SDL_Surface* loaded = NULL; SDL_Surface* opt = NULL; SDL_Surface* loadedopt = NULL; loadedopt = IMG_Load(filename.c_str()); if(loadedopt !=NULL) { loadedopt = SDL_DisplayFormat(loadedopt); SDL_FreeSurface(loadedopt); } return loadedopt; }[/CODE][/QUOTE] I didn't review your code in-depth, I barely skimmed over it, but this caught my eye: if loadedopt != NULL you do SDL_FreeSurface(loadedopt) and then return it. I'm guessing you're trying to use a free'd surface. In general, VS has a "Start Debugger"-button somewhere. Click it, it'll run and crash as well, but the debugger will halt the program at that point and you can examine its state, for example see at while line it crashed for a start. iirc [url]www.learncpp.com[/url] also has a few tutorials on the MSVC debugger. Check it out, knowing how to debug is an essential skill for programming.
[QUOTE=reevezy67;42323497]Also, C++ seems to be the language of choice on Facepunch at the moment, it was C# a couple of months ago IIRC. [editline]27th September 2013[/editline] Merge pirate.[/QUOTE] FP loves low-level imperatives. Also, maybe some of the C# people moved to the Unity thread. [highlight](User was permabanned for this post ("spamming on alts." - postal))[/highlight]
[QUOTE=reevezy67;42323478]I guess I'll ask again, Is there a way of doing this that will work without it spiraling outwards?[/QUOTE] Normalize the vector and multiply by the camera orbital distance (radius of the sphere) to bring the camera back onto the sphere.
[QUOTE=MakeR;42323692]Normalize the vector and multiply by the camera orbital distance (radius of the sphere) to bring the camera back onto the sphere.[/QUOTE] Hah! that was easy. Thank you very much.
[CODE] import java.util.Scanner; public class Project1 { public static void main(String[] args) { Scanner keyboard = new Scanner (System.in); // Variables for ordering String bookTitle; int booksOrdered; double publisherCost; double markUpNew; double newBook; double usedBook; double rentedBook; // User inputs System.out.println("What is the book title you are ordering today?"); bookTitle = keyboard.nextLine(); System.out.println("What is the publisher's cost?"); publisherCost =keyboard.nextDouble(); System.out.println("What is the quantity of books you would like to order?"); booksOrdered = keyboard.nextInt(); // Pricing quantity formulas if (booksOrdered < 20) { markUpNew = publisherCost * .40; } else if (booksOrdered >= 20 && booksOrdered < 50); { markUpNew = publisherCost * .35; } else if (booksOrdered >= 50 && booksOrdered < 100) { markUpNew = publisherCost * .30; } else { markUpNew = publisherCost * .25; } // Book quality formulas newBook = publisherCost + markUpNew; usedBook = newBook * .75; rentedBook = newBook * .40; // Generated outputs System.out.println("The book you have purchased: " + bookTitle); System.out.printf("The publisher's cost: $%.2f " + publisherCost); System.out.println("The quantity of books you have purchased: " +booksOrdered); System.out.printf("The price of a new book is: $%.2f \n" , newBook); System.out.printf("The price of a used book is: $%.2f \n" , usedBook); System.out.printf("The price of a used book is: $%.2f \n" , rentedBook); } }[/CODE] Hey guys, I'm working on a project for my intro to programming class with Java and could use some help cleaning it up. I'm running into an issue with my If else statements. I don't know if I'm forgetting something, but eclipse won't run it and claims I should delete my else if statement on line 43. Here's the project description: [QUOTE]As an employee of the University Book Store, your job is to determine the sales price (new and used) and rental price for textbooks. The price of a new book is the publisher’s cost plus markup. The markup amount varies depending on the number of books ordered by the bookstore. If fewer than 20 books are ordered, the markup is 40%. If at least 20 but fewer than 50 books are ordered, the markup is 35%. If at least 50 but fewer than 100 books are ordered, the markup is 30%, and if at least 100 books are ordered the markup is 25%. Used books are priced at 75% of the new book price, and rentals are 40% of the new book price. Once the price is calculated, your program should display the name of the book, the publisher’s price, the number of books ordered, the student price of a new book, the student price of a used book, and the student cost to rent the book.[/QUOTE]
[QUOTE=supersocko;42320024]So I started taking a programming class in college, and I have a small question that I feel is not thread-worthy. The professor is teaching us Java, but from what I hear, it isn't that great for game development which is what I want to get into. How screwed am I? Is Java similar enough to convert to another language later on?[/QUOTE] It's not perfect, but it's entirely feasible to make good games in Java. You can also apply almost anything to other languages because Java has less features than most others. Most programming experience is actually language-agnostic, the same way that you can give directions in French and German without looking them up twice. If/When you switch you should take care not to develop too much of an "accent" though. Many things that are necessary in Java are considered bad practice in e.g. C#, due to the better alternatives that are available in that language. [editline]27th September 2013[/editline] [QUOTE=blacksam;42324406]import java.util.Scanner;[/QUOTE] [code]else if (booksOrdered >= 20 && booksOrdered < 50);[/code] Delete the semicolon. You should also fix the indentation, if you get weird results from auto-formatting it's almost always pointing to a syntax error. [editline]edit[/editline] You don't need the >= parts in the conditions because that's already checked in the previous one. If you want to keep them I suggest you put one on the part for "at least 100" book too and add an else clause that throws an exception if it's reached. This means that the program won't fail silently if the specification is changed to a faulty one. (It also means negative order numbers are caught, if you add a lower bound to the first condition.) [editline]edit[/editline] The specification basically allows a loophole for negative or 0 books. Maybe the book store wants to waste money by always buying books expensively :v: Usually one would consult with the one who wrote the specification in this case, but it most likely doesn't matter whether you put in the sanity check.
Have my babies? Please? Thank you Tamschi!
[QUOTE=SteelSliver;42322023]I'm using SDL and I'm working on a framework/engine thing. Whenever I compile it, Visual Studio gives no errors and it just crashes whenever I try to load the program up. I don't know what's going on, and I was hoping you guys could give me some help. A lot of the code in here doesn't really do anything yet but heres the code that I've written(partially, most is from LazyFoo tuts :P) ...reams of code... Any input here would be most appreciated! Sorry if this is a little broad, but I'm kinda stumped.[/QUOTE] No compiler errors + unspecified runtime errors + wall of source code = please try debugging it. Not many people are going to sift through your code line by line to find the error. The only way we could help is by trying to compile it ourselves and then running it in a debugger, which you could do much easier. If you get the runtime error from the debugger and still don't understand what's wrong, then we'll probably be able to help.
[QUOTE=Naelstrom;42306632]Help provided earlier[/QUOTE] Thanks for helping me, [IMG]https://dl.dropboxusercontent.com/u/28926055/Thanks.png[/IMG] I was not buffering the data correctly, since I was passing the vertex array to the Renderable class it could not get the correct size anymore using sizeof, also discovered a small other flaw which I cannot rememeber but it works now :D
Could someone explain, in really simple terms, what a struct is and what it's used for. And the same for Delegates?
I hate having to ask for so much help with this. I want the camera to be able to rotate around the entity whilst the entity is moving around. This doesn't work when it is moving? [code] camera->position = camPos * distance [/code] So I tried this and a bunch of other things, nothing worked. [code] Vector3 delta = entity->position - camera->position; Vector3 dx = delta; dx = dx.crossProduct(GetUpwardVector(camera->rotation)); dx.Normalize(); Vector3 dy = delta; dy = dy.crossProduct(dx); dy.Normalize(); camera->position -= (dx*mouseAxis.x) + (dy*mouseAxis.y); Vector3 camPos = camera->position; camPos.Normalize(); // I figured adding the difference between where the entity started and where it is now would fix this but it just locks the camera in one place. camera->position = (camPos * distance) + (entity->position-entityStart); Quaternion quat = camera->getRotationQuat(); entity->setRotationQuat(quat.w,quat.x,quat.y,quat.z); camera->lookAt(entity->position); [/code] Thanks in advance.
Try this: [code]Vector3 delta = camera->position - entity->position; delta.Normalize(); Vector3 dx = delta.crossProduct(GetUpwardVector(camera->rotation)); dx.Normalize(); Vector3 dy = delta.crossProduct(dx); dy.Normalize(); delta -= dx*mouseAxis.x + dy*mouseAxis.y; delta.Normalize(); camera->position = entity->position + delta*distance; Quaternion quat = camera->getRotationQuat(); entity->setRotationQuat(quat.w,quat.x,quat.y,quat.z); camera->lookAt(entity->position);[/code]
[QUOTE=MakeR;42332942]Try this: [code]Vector3 delta = camera->position - entity->position; delta.Normalize(); Vector3 dx = delta.crossProduct(GetUpwardVector(camera->rotation)); dx.Normalize(); Vector3 dy = delta.crossProduct(dx); dy.Normalize(); delta -= dx*mouseAxis.x + dy*mouseAxis.y; delta.Normalize(); camera->position = entity->position + delta*distance; Quaternion quat = camera->getRotationQuat(); entity->setRotationQuat(quat.w,quat.x,quat.y,quat.z); camera->lookAt(entity->position);[/code][/QUOTE] Perfect, thanks.
-snip-
Not to be rude but I think you might want to look in this thread: [url]http://facepunch.com/showthread.php?t=1250244&page=41[/url]
[QUOTE=mobrockers;42333373]Not to be rude but I think you might want to look in this thread: [url]http://facepunch.com/showthread.php?t=1250244&page=41[/url][/QUOTE] I didn't make a thread?
[QUOTE=SammySung;42333441]I didn't make a thread?[/QUOTE] You're asking web dev questions, that thread is for web dev..
[QUOTE=Pelf;42331196]Could someone explain, in really simple terms, what a struct is and what it's used for. And the same for Delegates?[/QUOTE] C#? A struct is basically a grouping of data that's moved around as value instead of a reference. If you have a class it basically behaves this way: [code]stack: ####ref1#### heap: ###################### instanceHeader+fields // line is at location ref1 ######################[/code] (The stack contains the variables of the currently running method and a few other things. # is other data.) With a struct you get [code]stack: ####fields####[/code] instead. As there's no instance header there can be no dynamic selection of methods. In fact, all struct methods can't be virtual under usual circumstances. If you cast a struct to an interface (which needs virtual methods), the struct is boxed: You end up with the same image as if there was a class in the first place. The instance header points to a method table that translates virtual calls to the right direct ones. The fact that with structs the fields are copied around by default means that there are often copies made where you don't immediately expect it. If you cast a struct to an interface and call a mutating method that has no effect on the original for example, because the boxed version is a copy that is discarded afterwards. For this reason, it's usually a good idea to make struct fields readonly. Delegates are basically a combination of target and method references: Instance methods alone don't know the instance because each method exists once and is just called with different [B]instances as parameter[/B]. They do know whether they are instance methods though. The delegate contains enough information to call the method, if the method is static the target is null. In C# all delegates are actually MulticastDelegates, meaning they can store more than one target and method. You can see this with events for example, which are a different way of declaring a private delegate and exposing the += and -= operations. The + and - operators of MulticastDelegate are shorter ways manipulating these target lists. (I'm pretty sure the delegates are usually immutable.) There's a caveat here: While you can cast certain delegates (e.g. Action<object> to Action<Something>), trying to add them with the + operator afterwards will usually fail if the native types are different. You can rebuild both delegates manually though, by getting the invocation lists and either wrapping the method and target in a lambda each or building the call with Expressions. You could also just wrap the delegate in a lambda, but then there's an overhead when calling the result.
Have you ever spent about 3-4 hours trying to do something you've never done before and have it end up dying on you because of a simple techicality and you have to toss it all away because the documentation is extremely shitey for the third party library you're using? I just finished writing the basics for what I think would be an entity manager for Slick2D but then it wouldn't load the bloody images for the entities. :\ I want to give up but I felt I was so close and now I want to rewrite it so it's better but ughhhh If anyone want to look at my abortion of code I have produced here it is [url]https://www.dropbox.com/sh/xxn3ccg6khmj2k9/HVVx6J40uF[/url] If you want to recommend improvements, go ahead. I dunno if I'll use it or not. :\ e This is the error im getting [code]WARN:class org.newdawn.slick.opengl.PNGImageData failed to read the data java.lang.UnsupportedOperationException: Unsupported format for this image[/code] Even though I'm using the exact same PNG's in another state, it refuses to work in this situation.
Here is a simpler example of my question: [code] #include <stdio.h> #include <string.h> #include <stdio.h> #include <stdlib.h> typedef struct Student{ int grade; char * name; struct Student * next; } Student; void initializeStudent(char * name, int grade, Student * X){ X=malloc(sizeof(Student)); X->name=malloc(sizeof(strlen(name)+1)); X->grade=grade; printf("Given name: %s\n",name); strcpy(X->name,name); printf("After name: %s\n",X->name); } int main(void){ Student s; initializeStudent("Aidan",100,&s); printf("Main name: %s\nMain grade: %d\n",s.name,s.grade); return 0; } [/code] Given name: Aidan After name: Aidan Main name: 1&#65533;I&#65533;&#65533;^H&#65533;&#65533;H&#65533;&#65533;&#65533;PTI&#65533;&#65533;@@ Main grade: 0
[QUOTE=bull3tmagn3t;42339176]Here is a simpler example of my question: Given name: Aidan After name: Aidan Main name: 1&#65533;I&#65533;&#65533;^H&#65533;&#65533;H&#65533;&#65533;&#65533;PTI&#65533;&#65533;@@ Main grade: 0[/QUOTE] [code] #include <stdio.h> #include <string.h> #include <stdio.h> #include <stdlib.h> typedef struct Student{ int grade; char * name; struct Student * next; } Student; void initializeStudent(char * name, int grade, Student * X){ // This is your issue here. When you call initializeStudent later, you're // referencing the variable s (which is on the stack) - I'm not even // sure what this does. The rest of this function should work without // this line, only if you use it as you do below. X=malloc(sizeof(Student)); X->name=malloc(sizeof(strlen(name)+1)); X->grade=grade; printf("Given name: %s\n",name); strcpy(X->name,name); printf("After name: %s\n",X->name); } int main(void){ Student s; initializeStudent("Aidan",100,&s); printf("Main name: %s\nMain grade: %d\n",s.name,s.grade); return 0; } [/code] Using s on the stack: [url]https://eval.in/private/a5b89c44b5a31e[/url] or, the alternative: [url]https://eval.in/private/8839626c06ce16[/url] I hope I did this right :tinfoil:
I'm trying to write a function in C++ that will traverse a Linked List and remove the first node with the given value. [code] void removeFirst(string text) { Node *prev = n.head; Node *curr = n.head; while (curr != NULL) { if (curr->data == text) { prev->next = curr->next; delete curr; break; } else { prev = curr; curr = curr->next; } } } [/code] This works except when the first node with the given value is also the first node in the Linked List. Edit: I just added an if statement that calls my delete first function if curr == n.head. It's working. Also, there's a constraint that each string added to the linked list has to be 4 characters or less, when I test that, should I call a separate function to print the error message or should I just cout the error message in the add function? I know it doesn't really matter but I'm wondering if there's a conventional way to do it.
[QUOTE=wlitsots;42341077]Also, there's a constraint that each string added to the linked list has to be 4 characters or less, when I test that, should I call a separate function to print the error message or should I just cout the error message in the add function? I know it doesn't really matter but I'm wondering if there's a conventional way to do it.[/QUOTE] The "conventional" way to do such a thing is to just fail to do it and return an error. Make your "add" function return a bool and return false if it fails.
All I need is one cell in a JTable to have bold text. Just one damn cell. Not one row, not one column, one single cell. I say it like this because, believe me, I've been trying to find a solution, but it's never for a single cell. I have the coordinates, or row and column, at which the cell lies, and I need the text within it to become bold when a Boolean value becomes true. This is of course in Java, hence the JTable. I assume it has something to do with [url=http://docs.oracle.com/javase/7/docs/api/javax/swing/table/DefaultTableCellRenderer.html]DefaultTableCellRenderer()[/url], but I've looked at the documentation for it and apparently I'm dumb as fuck because I have no idea what to do with it. Thanks in advance for any help.
stratch that, I need a good source to learn C# or C++ I am confident my programming knowledge is interchangeable enough for me to pick up one of these. Also which one would I pick if I were going to make 2D games by myself?
[QUOTE=Pat.Lithium;42365614]I've been writing small programs in Java using notepad++ for a little while now and have been using gamemaker to make games for far too long, what IDE would best suit me?[/QUOTE] Eclipse I guess.
Sorry, you need to Log In to post a reply to this thread.