• What do you need help with? Version 1
    5,001 replies, posted
You don't need to. You only need to hold 120 because if you know that the following number has 2 bytes you know that you have to multiply the first byte with 256.
[QUOTE=Dlaor;22400505]Super quick question time! How do I draw a rectangle with white outlines and black filling in XNA, C#?[/QUOTE] Super late answer time! [code] //don't redefine this each frame :D Rectangle rect = new Rectangle(x, y, w, h); //tex_pixel is a 1x1 pure white texture sprBatch.Draw(tex_pixel, rect, Color.White); rect.Inflate(-2, -2); //border width = 2 sprBatch.Draw(tex_pixel, rect, Color.Black); [/code] Bear in mind that you'll have to reinflate the rectangle to its original size each time unless you define it on the spot also the borders will start at the XY pos, not the actual black rectangle
[QUOTE=Darwin226;22403719]You don't need to. You only need to hold 120 because if you know that the following number has 2 bytes you know that you have to multiply the first byte with 256.[/QUOTE] Well how do I perform arithmetic on that? [editline]12:09AM[/editline] Found out how to do it, use the bytes like 2 digits of a base 256 number, sort of.
[QUOTE=Dacheet;22402904]No, I'm trying to compare a string to various strings.[/QUOTE] Well, in that code you're comparing a number. MAXITEMS is a number that is equal to 7. You're saying 'if 7 is equal to "Money", or 7 is equal to "money", etc' so I still don't understand I'm not trying to be mean (now I understand layla) but it seems like you actually need to learn the language a bit more before you try to do stuff with it
[QUOTE=NovembrDobby;22404854]Super late answer time! [code] //don't redefine this each frame :D Rectangle rect = new Rectangle(x, y, w, h); //tex_pixel is a 1x1 pure white texture sprBatch.Draw(tex_pixel, rect, Color.White); rect.Inflate(-2, -2); //border width = 2 sprBatch.Draw(tex_pixel, rect, Color.Black); [/code] Bear in mind that you'll have to reinflate the rectangle to its original size each time unless you define it on the spot also the borders will start at the XY pos, not the actual black rectangle[/QUOTE] Thanks! :buddy:
Hope I can post this here... So I have a book on C++, and I'm kind of stuck... Write now it's having me write some code for a "Prime Number Test". Here is the code: [code] #include <iostream> #include <math.h> using namespace std; int main() { int n; int i; int is_prime; is_prime = true; cout << "Enter a number and press ENTER: "; cin >> n; i = 2; while (i <= sqrt(static_cast<double>(n))) { if (n % i == 0) { is_prime = false; } i++; } if (is_prime) { cout << "Number is prime."; } else { cout << "Number is not prime."; } return 0; } [/code] Now, at the end of each section, it has an exercise to try it out. So far I've been doing them all pretty well, but this one just has me stumped. Here's what it wants me to do: [quote] Optimize the program further by calculating the square root of n just once rather than over and over as was done in the example. To perform this optimization, you'll need to declare another variable and set it to the square root of n. The type should be [B]double[/B]. You can then use this variable in the [B]for[/B] loop condition. [/quote] I'm not really sure what to do. Any help would be appreciated. Also, this is something that the book didn't really touch on. [code] while (i <= [B]sqrt((static_cast<double>)n))[/B]) [/code] I'm assuming this part takes the int n and changes it from an int to a double. Right?
[cpp]static_cast<type>(variable)[/cpp] performs a [i]static_cast[/i] (there are 3 more, but the book will probably get to that later) on [i]variable[/i] to the type [i]type[/i]. [cpp]sqrt(n)[/cpp] just calculates the [b]sq[/b]uare[b]r[/b]oo[b]t[/b] of n. These explanations might make it possible for you to come up with the solution yourself :) If not, just say so.
I believe that the compiler would optimize that for you. With the sqrt and such as the conditional for while loop, without optimizations, it would be re-evaluated each time through the loop. So how can you calculate it only once?
I just looked at some of the sockets code here : [url]http://msdn.microsoft.com/en-us/library/fx6588te.aspx[/url] Does anyone know how to keep track of who already joined so they can't connect again ? I thought of keeping a list of stateObjects but I don't know how to compare them ....
[lua] public void DoWrite(string DWName, int DWPassword, int DWCash) { using (StreamWriter WriteText = new StreamWriter("c:\\accountlog.txt",true)) { WriteText.WriteLine(DWName); WriteText.WriteLine(DWPassword); WriteText.WriteLine(DWCash); } }[/lua] As you see I'm writing into the "accountlog.txt" . What is the best way to find a string in the log? I'm sure you are aware that I'm trying to make some kind of login system. Just for fun, nothing serious.
[QUOTE=quincy18;22440217]I just looked at some of the sockets code here : [url]http://msdn.microsoft.com/en-us/library/fx6588te.aspx[/url] Does anyone know how to keep track of who already joined so they can't connect again ? I thought of keeping a list of stateObjects but I don't know how to compare them ....[/QUOTE] You can compare IPAddresses though (hint: RemoteEndPoint). [QUOTE=Swebonny;22440291][lua] public void DoWrite(string DWName, int DWPassword, int DWCash) { using (StreamWriter WriteText = new StreamWriter("c:\\accountlog.txt",true)) { WriteText.WriteLine(DWName); WriteText.WriteLine(DWPassword); WriteText.WriteLine(DWCash); } }[/lua] As you see I'm writing into the "accountlog.txt" . What is the best way to find a string in the log? I'm sure you are aware that I'm trying to make some kind of login system. Just for fun, nothing serious.[/QUOTE] Simply use a StreamReader, read the lines and use String.Equals or String.Constains, whichever you need. Also, lua-tags?!
[QUOTE=ZeekyHBomb;22441139]You can compare IPAddresses though (hint: RemoteEndPoint). Simply use a StreamReader, read the lines and use String.Equals or String.Constains, whichever you need. Also, lua-tags?![/QUOTE] Yea, thought of that, but I tried it with a friend and he had some sort of dynamic ip which would change his last 2 ip numbers :(
I'm having a huge nightmare and I can't figure out why this isn't working. I have main class BODY and a subclass RECTANGLE. Body has a function called SetWorld which sets the values of self.world. So If I call this function on RECTANGLE it should work. Now, if I do this. [code]rect:SetWorld(1)[/code] The value self.world is changed to 1 in the function. I know this happens I've checked it. but later on in the body class file, in another function if I call self.world it's nil. Why is this? It works 100% if I do BODY:SetWorld(1)
Maybe the wrong protection level on the world variable.
[QUOTE=quincy18;22441626]Yea, thought of that, but I tried it with a friend and he had some sort of dynamic ip which would change his last 2 ip numbers :([/QUOTE] The IP Address shouldn't change while connected. If it does, the old connection should become unresponsive/timeout then. Did you friend do anything fancy before connecting a second time? Also, you probably mean the first hexadecimal digit.
[quote].NET class library is all about classes, not interfaces. Extensive use of interfaces is oficially discouraged.[/quote] Does anyone else think that this doesn't make any sense? I mean, of course a CLASS library is all about classes and this sentence makes classes and interfaces basically the same thing. (I know it's off topic but my friend is trying to be smart and throws random quotes from the internet without knowing what he's talking about so I'd like to hear what you think)
[QUOTE=ZeekyHBomb;22442106]The IP Address shouldn't change while connected. If it does, the old connection should become unresponsive/timeout then. Did you friend do anything fancy before connecting a second time? Also, you probably mean the first hexadecimal digit.[/QUOTE] Well I made a connect button, that create's a new socket to the server and he just spammed it and it keeped saying someone connected from : IP and the last 2 digits kept changing
[QUOTE=quincy18;22442716]Well I made a connect button, that create's a new socket to the server and he just spammed it and it keeped saying someone connected from : IP and the last 2 digits kept changing[/QUOTE] Just disable the Connect button while you're connected.
[QUOTE=Z_guy;22442916]Just disable the Connect button while you're connected.[/QUOTE] Never thought of that, so simple yet so effective.
[QUOTE=ZeekyHBomb;22437560]static_cast<type>(variable) performs a [I]static_cast[/I] (there are 3 more, but the book will probably get to that later) on [I]variable[/I] to the type [I]type[/I]. sqrt(n) just calculates the [B]sq[/B]uare[B]r[/B]oo[B]t[/B] of n. These explanations might make it possible for you to come up with the solution yourself :) If not, just say so.[/QUOTE] I don't really understand what the static_cast is though. Also, I don't know if I did this right or not [code] #include <iostream> #include <math.h> using namespace std; int main() { int n; int i; int is_prime; int x; is_prime = true; cout << "Enter a number and press ENTER: "; cin >> n; i = 2; x = sqrt(n); if (i <= x) { if (n % i == 0) { is_prime = false; } i++; } if (is_prime) { cout << "Number is prime."; } else { cout << "Number is not prime."; } return main(); } [/code] Is this optimized? .__ .
No. It doesn't even find the prime. And repeatedly calling main is a bad idea, besides it goes on forever, until your program is forced to exit. You are caching the value of sqrt(n), which is good, but you are only checking if it's not a prime once, which is not enough. static_cast tells the compiler to perform a cast of a variable of one type to another, this means that the compiler tries to transform the type of it.
[QUOTE=ZeekyHBomb;22452948]No. It doesn't even find the prime. And repeatedly calling main is a bad idea, besides it goes on forever, until your program is forced to exit. You are caching the value of sqrt(n), which is good, but you are only checking if it's not a prime once, which is not enough. static_cast tells the compiler to perform a cast of a variable of one type to another, this means that the compiler tries to transform the type of it.[/QUOTE] The book says to [quote]Optimize the program further by calculating the square root of n just [U][B]once[/B][/U] rather than over and over as was done in the example.[/quote] How might I do this?
calculating != checking :D You are calculating it once, which is good, but you still have to check for each new i.
So all I have to do is change the first IF to a WHILE and it'll be good?
Exactly :) You could also just have tested it :P
Oook that was just confusing the heck out of me. Didn't realize it was that simple :P
[QUOTE=Darwin226;22442154]Does anyone else think that this doesn't make any sense? I mean, of course a CLASS library is all about classes and this sentence makes classes and interfaces basically the same thing.[/QUOTE] An interface is basically a special type of class, and there's nothing wrong with using them where they're appropriate, for abstraction. There's also nothing wrong with having interfaces in a class library. Of course, one could go overboard and give [i]every[/i] class a corresponding interface, and that would be bad since in most cases they wouldn't provide any real value, and would just make the code more difficult to maintain.
ok i guess i have a question about some sort of Level-Of-Detail Algorithm for XNA. i am a complete noob at level of detail, but i can draw a terrain relatively easily. i want to know how to add LOD so i can make a massive terrain without uberlag. is there any good sites that have stuff on LOD for noobs? i've searched around and didnt find much. all i know is that i would like to use chunked lod because ive heard its the easiest
Should I learn HTML before learning javascript or is it not neccesary? I've only used scripting languages like LSL and Lua before.
[QUOTE=Collin665;22507246]Should I learn HTML before learning javascript or is it not neccesary? I've only used scripting languages like LSL and Lua before.[/QUOTE] HTML is a markup language, and is not directly related to JavaScript in any way. However, f you want to do JavaScript for client-side browser scripting, then yes, you should definitively get a rudimentary understanding of HTML first.
Sorry, you need to Log In to post a reply to this thread.