What exactly is the purpose for error handling at these kinds of statements? I see a lot of code like this when im browsing and just wondering if it's something i should get used to doing.
[CPP]if (!texture.loadFromFile("cb.bmp"))
return EXIT_FAILURE;[/CPP]
Well, basically, if the load fails, whatever it is that's trying to do it returns with an error code. Don't know why the return is called what it is.
I prefer Exceptions. No need for a return value, can handle it in any way I want, ...
[editline]6th February 2013[/editline]
[QUOTE=ProWaffle;39492452]I'm trying to pick out a C++ IDE for use on Windows. Am I best to use Visual Studio? I'd like to do some cross-platform stuff, is it going to inhibit code portability if I'm only using portable libraries?[/QUOTE]
Eclipse CDT is quite good, I recommend it with MinGW ([url=http://nuwen.net/mingw.html]this one specifically[/url], it has the newest GCC)
EXIT_FAILURE is a standard #define in C and C++, it always equals something other than 0, since EXIT_SUCCESS is 0.
I only lurk in this sub-forum as a wannabe programmer, but I came across [url="http://en.wikipedia.org/wiki/Year_2038_bug"]this wikipedia article[/url] and I was wandering if somebody could explain it too me. Don't even know if this is the right place to ask!
[QUOTE=whatthe;39493664]I only lurk in this sub-forum as a wannabe programmer, but I came across [url="http://en.wikipedia.org/wiki/Year_2038_bug"]this wikipedia article[/url] and I was wandering if somebody could explain it too me. Don't even know if this is the right place to ask![/QUOTE]
The number of seconds since UTC will be too large to store in the amount of space they've reserved for it.
[QUOTE=Zally13;39491948]Quick Python question.
How would one go about (if possible) writing a for loop that ends once a condition is met.[/QUOTE]
Use the break statement. See [url]http://www.network-theory.co.uk/docs/pytut/breakandcontinueStatements.html[/url]
[QUOTE=Zally13;39491948]Quick Python question.
How would one go about (if possible) writing a for loop that ends once a condition is met. I'm using a while loop in this code:
[code]if stats != 0:
print "You have %d points left over." % stats
print "You have %d Body and %d Mind." % (body, mind)
print "You must spend all your points!"
while x != 2:
if stats != 0:
while x == 1:
print "How much do you wish to put into Body?"
temp = int(raw_input("> "))
body += temp
stats -= temp
if ((body <= 3 and body >= 0) and stats >= 0):
print "You have %d points in Body!" % body
x = 0
else:
stats += temp
body -= temp
print "That's invalid."
if stats != 0:
while x == 0:
print "How much do you wish to put into Mind?"
temp = int(raw_input("> "))
mind += temp
stats -= temp
if ((mind <= 3 and mind >= 0) and stats >= 0):
print "You have %d points in Mind!" % mind
x = 1
else:
stats += temp
mind -= temp
print "That's invalid."
else:
x = 2[/code]
Basically I just set x = 2 in order to end the loop, but I was wondering if there was a way to do so in a for loop, as I hear it's much better to use when possible. Basically it checks if the user hasn't used all their "stat points", and if so, forces them to put the points into the stats.[/QUOTE]
Well I don't know about Python but usually you could use "break", as such:
[code]
int x = 0;
while(true)
{
print "I'll keep doing this"
x++;
if(x == 100)
{
break;
}
}
[/code]
or
[code]
for(int i = 0; i < 10; i++)
{
//When i = 8, stop the loop.
if(i==8)
{
break;
}
}
[/code]
[QUOTE=Zally13;39491948]Quick Python question.
How would one go about (if possible) writing a for loop that ends once a condition is met. I'm using a while loop in this code:
[code]if stats != 0:
print "You have %d points left over." % stats
print "You have %d Body and %d Mind." % (body, mind)
print "You must spend all your points!"
while x != 2:
if stats != 0:
while x == 1:
print "How much do you wish to put into Body?"
temp = int(raw_input("> "))
body += temp
stats -= temp
if ((body <= 3 and body >= 0) and stats >= 0):
print "You have %d points in Body!" % body
x = 0
else:
stats += temp
body -= temp
print "That's invalid."
if stats != 0:
while x == 0:
print "How much do you wish to put into Mind?"
temp = int(raw_input("> "))
mind += temp
stats -= temp
if ((mind <= 3 and mind >= 0) and stats >= 0):
print "You have %d points in Mind!" % mind
x = 1
else:
stats += temp
mind -= temp
print "That's invalid."
else:
x = 2[/code]
Basically I just set x = 2 in order to end the loop, but I was wondering if there was a way to do so in a for loop, as I hear it's much better to use when possible. Basically it checks if the user hasn't used all their "stat points", and if so, forces them to put the points into the stats.[/QUOTE]
Why are you not just doing
[cpp]
while stats != 0:
print "You have %d points left over." % stats
print "You have %d Body and %d Mind." % (body, mind)
print "You must spend all your points!"
print "How much do you wish to put into Body?"
temp = int(raw_input("> "))
body += temp
stats -= temp
if ((body <= 3 and body >= 0) and stats >= 0):
print "You have %d points in Body!" % body
else:
stats += temp
body -= temp
print "That's invalid."
print "How much do you wish to put into Mind?"
temp = int(raw_input("> "))
mind += temp
stats -= temp
if ((mind <= 3 and mind >= 0) and stats >= 0):
print "You have %d points in Mind!" % mind
else:
stats += temp
mind -= temp
print "That's invalid."
[/cpp]
This should do it no? Kind of, I haven't really looked if it breaks anything.
[QUOTE=mobrockers2;39493771]The number of seconds since UTC will be too large to store in the amount of space they've reserved for it.[/QUOTE]
so does this require a different paradigm of computing architecture? Kind of like the difference between IPv4/v6, or 32/64bit? I always of thought one of the fundamental properties of binary is limitless? Or have I got the wrong end of the stick here?
[QUOTE=whatthe;39495301]so does this require a different paradigm of computing architecture? Kind of like the difference between IPv4/v6, or 32/64bit? I always of thought one of the fundamental properties of binary is limitless? Or have I got the wrong end of the stick here?[/QUOTE]
The time is stored as the number of seconds since 00:00:00 UTC on Thursday, 1 January 1970 in a signed 32-bit integer (which has a range of –2,147,483,648 to 2,147,483,647). At 03:14:07 UTC on Tuesday, 19 January 2038 the maximum range of a signed 32-bit integer will be reached and the integer will therefore overflow and the time will jump back to 1901.
This happens because of the range limit of 32-bit integers. On 64-bit operating systems (time is stored in a signed 64-bit integer) the time will overflow at 15:30:08 on Sunday, 4 December 292,277,026,596.
[QUOTE=whatthe;39495301]so does this require a different paradigm of computing architecture? Kind of like the difference between IPv4/v6, or 32/64bit? I always of thought one of the fundamental properties of binary is limitless? Or have I got the wrong end of the stick here?[/QUOTE]
Just the format of the date is going to be greater than the data type its recorded in. This only applies to unix time, it is not the only time format that computers use.
[code]
public void SetText(String text, String ider){
TextView temp = (TextView)findViewById(id.ider);
temp.setText(text);
}
[/code]
Basically, argument named "text" goes alright, and works well, but if I try to call function and parse argument named "ider" which is supposed to be ID of label/text it fails to do so. I know it's because of id.ider but I am not sure how to fix it?
Something like id.+ider ? help?
It's Java btw.
[QUOTE=MakeR;39495416]The time is stored as the number of seconds since 00:00:00 UTC on Thursday, 1 January 1970 in a signed 32-bit integer (which has a range of –2,147,483,648 to 2,147,483,647). At 03:14:07 UTC on Tuesday, 19 January 2038 the maximum range of a signed 32-bit integer will be reached and the integer will therefore overflow and the time will jump back to 1901.
This happens because of the range limit of 32-bit integers. On 64-bit operating systems (time is stored in a signed 64-bit integer) the time will overflow at 15:30:08 on Sunday, 4 December 292,277,026,596.[/QUOTE]
I rated funny because I didn't realize how simple the solution is. So this will only cause problems with people on 32 bit Operating Systems?
[QUOTE=whatthe;39493664]I only lurk in this sub-forum as a wannabe programmer, but I came across [url="http://en.wikipedia.org/wiki/Year_2038_bug"]this wikipedia article[/url] and I was wandering if somebody could explain it too me. Don't even know if this is the right place to ask![/QUOTE]
Imma just gonna put this here:
[video=youtube;QJQ691PTKsA]http://www.youtube.com/watch?v=QJQ691PTKsA&list=UUoxcjq-8xIDTYp3uz647V5A&index=3[/video]
[QUOTE=whatthe;39497347]I rated funny because I didn't realize how simple the solution is. So this will only cause problems with people on 32 bit Operating Systems?[/QUOTE]
Yeah. Anything that represents time in 32 bits. And the funny thing is since it's signed, when it reaches the max it'll go to the negative max - which will correspond to sometime in 1901 :v:
--fixed this--
[editline]6th February 2013[/editline]
Is there an easy way of killing specific threads in python?
This is my current setup (roughly):
[url]http://pastebin.com/axXSNTsa[/url]
[QUOTE=arleitiss;39497308][code]
public void SetText(String text, String ider){
TextView temp = (TextView)findViewById(id.ider);
temp.setText(text);
}
[/code]
Basically, argument named "text" goes alright, and works well, but if I try to call function and parse argument named "ider" which is supposed to be ID of label/text it fails to do so. I know it's because of id.ider but I am not sure how to fix it?
Something like id.+ider ? help?
It's Java btw.[/QUOTE]
I have no clue what you're trying to do here, could you explain? In any case id.ider would be used to call the variable ider of object id and I don't think that's what you're trying to do here.
[editline]6th February 2013[/editline]
[QUOTE=Mega1mpact;39497487]--fixed this--
[editline]6th February 2013[/editline]
Is there an easy way of killing specific threads in python?
This is my current setup (roughly):
[url]http://pastebin.com/axXSNTsa[/url][/QUOTE]
A thread should kill itself when it has nothing else to do ( at least in Java ).
[QUOTE=mobrockers2;39498031]I have no clue what you're trying to do here, could you explain? In any case id.ider would be used to call the variable ider of object id and I don't think that's what you're trying to do here.
[editline]6th February 2013[/editline]
A thread should kill itself when it has nothing else to do ( at least in Java ).[/QUOTE]
Basically I got project given in college to make an Android app,
in my main class I have basically a thing when you click button it makes a text label/TextView change text. For this I have to copy and paste always:
[code] TextView tv = (TextView)findViewById(id.texter);
tv.setText("LOOOL");
"texter" beside ID is ID of the label/text.
[/code]
so instead of copy/paste I decided to write a function for it.
[code]
public void SetText(String text, String ider){
TextView temp = (TextView)findViewById(id.ider);
temp.setText(text);
}[/code]
I tried assigning parsed argument as ID, but it doesn't work.
So yeah.
[QUOTE=mobrockers2;39498031]A thread should kill itself when it has nothing else to do ( at least in Java ).[/QUOTE]
That's the problem. It always has something to do.
Also it doesn't have to be stopped in a peaceful way.
[QUOTE=Mega1mpact;39498181]That's the problem. It always has something to do.
Also it doesn't have to be stopped in a peaceful way.[/QUOTE]
I don't think it's safe to stop a thread when it's doing stuff.
What my Java tutor recommends is to put whatever your thread has to do in a while loop, and set the condition in the while to false when the thread has to die.
[QUOTE=mobrockers2;39498235]I don't think it's safe to stop a thread when it's doing stuff.[/QUOTE]
All it's doing is listening to a connection until it gets a message. When it does it passes that message to a callback.
I can throw the connection away without the server giving a damn because it's Telnet
[QUOTE=arleitiss;39498118]Basically I got project given in college to make an Android app,
in my main class I have basically a thing when you click button it makes a text label/TextView change text. For this I have to copy and paste always:
[code] TextView tv = (TextView)findViewById(id.texter);
tv.setText("LOOOL");
"texter" beside ID is ID of the label/text.
[/code]
so instead of copy/paste I decided to write a function for it.
[code]
public void SetText(String text, String ider){
TextView temp = (TextView)findViewById(id.ider);
temp.setText(text);
}[/code]
I tried assigning parsed argument as ID, but it doesn't work.
So yeah.[/QUOTE]
I'm not sure what you mean by always, you'd only have to do it once right?
[QUOTE=mobrockers2;39498319]I'm not sure what you mean by always, you'd only have to do it once right?[/QUOTE]
Well:
If I solve this issue with my crappy function then yeah only once,
but if I don't I will end up copy/pasting that piece of code about 60 times per each page.
[QUOTE=arleitiss;39498429]Well:
If I solve this issue with my crappy function then yeah only once,
but if I don't I will end up copy/pasting that piece of code about 60 times per each page.[/QUOTE]
How can you possible have 60 TextViews per page..
Im starting a Java Programming course tomorrow for school, but I dont really want to learn Java as it wont have much use to me at all for modding. But what I would like to know, is it a good idea to learn java and is it relatively easy? Would it also be a good transition into C++?
[QUOTE=mobrockers2;39498766]How can you possible have 60 TextViews per page..[/QUOTE]
It was bit of exaggeration, I meant a lot of copying.
[editline]7th February 2013[/editline]
[QUOTE=Shirky;39499041]Im starting a Java Programming course tomorrow for school, but I dont really want to learn Java as it wont have much use to me at all for modding. But what I would like to know, is it a good idea to learn java and is it relatively easy? Would it also be a good transition into C++?[/QUOTE]
When I started College we did Java too. Tbh I thought that's crap but then I went into learning PHP myself and I find it pretty easy, PHP, JS, C#. Java has lots of bitchy things in my opinion such as you have to think what variable type you want? int, double, float, String?, char, bool, etc..
While in things like PHP it's simple just write $newVar = bla bla and done.
Java really helped me to learn basics, the rest if up to person.
[QUOTE=arleitiss;39499843]It was bit of exaggeration, I meant a lot of copying.
[editline]7th February 2013[/editline]
When I started College we did Java too. Tbh I thought that's crap but then I went into learning PHP myself and I find it pretty easy, PHP, JS, C#. Java has lots of bitchy things in my opinion such as you have to think what variable type you want? int, double, float, String?, char, bool, etc..
While in things like PHP it's simple just write $newVar = bla bla and done.
Java really helped me to learn basics, the rest if up to person.[/QUOTE]
I still don't understand why you need more than one, possibly two.
[QUOTE=arleitiss;39499843]It was bit of exaggeration, I meant a lot of copying.
[editline]7th February 2013[/editline]
When I started College we did Java too. Tbh I thought that's crap but then I went into learning PHP myself and I find it pretty easy, PHP, JS, C#. Java has lots of bitchy things in my opinion such as you have to think what variable type you want? int, double, float, String?, char, bool, etc..
While in things like PHP it's simple just write $newVar = bla bla and done.
Java really helped me to learn basics, the rest if up to person.[/QUOTE]
Im looking to learn the basics, so I guess it will be a good start.
Can anyone tell me what's wrong with this SFML and C++ function to highlight the outline of a rectangle around a text object?
[cpp]void Menu::MenuItem::highlightRectOutline(sf::RenderWindow &window, Text text, sf::Color color) {
sf::RectangleShape outlineRect;
sf::Vector2f size(text.getWidth(), text.getHeight());
outlineRect.setSize(size);
outlineRect.setPosition(text.getPosition());
outlineRect.setFillColor(sf::Color::Transparent);
outlineRect.setOutlineColor(color);
outlineRect.setOutlineThickness(5);
window.draw(outlineRect);
}[/cpp]
Thanks.
Sorry, you need to Log In to post a reply to this thread.