ZFGC

Resources => Coding => Topic started by: Infinitus on June 24, 2008, 11:53:57 pm

Title: Programming Q&A
Post by: Infinitus on June 24, 2008, 11:53:57 pm
Seeing as 4Sword was having a go at me for not replying to a C++ programming PM from him due to my unfortunate state of being asleep. I figured I would make this topic to help out a bit.

If you have any question about programming (any language you choose) that are to trivial to warrent their own topic; syntax errors, not unstanding certain concepts, etc. Post them here and I'll make sure either I or one of the other programmers on this forum gives you a reply.

When posing a question please include relavent information (source code that produce the error, etc) to help make answers faster.

(Be aware however this isn't a 'How do I build blank engine' topic, those questions should be in their own topics).

Have at it.
Title: Re: Programming Q&A
Post by: Porkchop on June 25, 2008, 12:02:38 am
How do I built engine?

(I just had to...)

Edit: Maybe I should make this a more serious post.

I'm interested in learning a language (GameMaker is... meh), what would be best for me to start? (Not really much knowledge of previous languages.... BASIC BASIC GML THAT'S IT.)
Title: Re: Programming Q&A
Post by: Infinitus on June 25, 2008, 12:11:49 am
Quote
I'm interested in learning a language (GameMaker is... meh), what would be best for me to start? (Not really much knowledge of previous languages.... BASIC BASIC GML THAT'S IT.)
Simplest way of getting into programming is probably by using a BASIC varient, BlitzMax (www.blitzbasic.com), Free Basic (http://www.freebasic.net), .etc, .etc. They tend to have a more abstract higher level interface than languages like C++, and tend to take the burden off the programmer for things like memory management, bounds checking, .etc, .etc. Meaning you can get to do the things you want faster without having to worry about any of the tedious 'behind-the-scene' stuff.

Once you've chosen a language the best way of really getting to grips with it (and importantly the logical methodoligy that goes behind it) is simply through experimentation, try creating a few simple but ambitious games, you may well fail but I can guarantee you will learn more about the language each time you do. Stick with the simple aspects of the language (IF statements, While statements, .etc) while your learning then once you've got the basics down try skimming through some language references and try out some of the more advanced stuff using the same experimentation method, after a while you will being to expand your knowledge of programming a great deal and will be able to do larger scale projects on your own.


/ Long badly spelt post.
Title: Re: Programming Q&A
Post by: Xiphirx on June 25, 2008, 12:35:38 am
How do I built engine?

(I just had to...)

Edit: Maybe I should make this a more serious post.

I'm interested in learning a language (GameMaker is... meh), what would be best for me to start? (Not really much knowledge of previous languages.... BASIC BASIC GML THAT'S IT.)

I would suggest to start with QBASIC > Javascript > BlitzMax > ???
Title: Re: Programming Q&A
Post by: Infinitus on June 25, 2008, 12:37:27 am
How do I built engine?

(I just had to...)

Edit: Maybe I should make this a more serious post.

I'm interested in learning a language (GameMaker is... meh), what would be best for me to start? (Not really much knowledge of previous languages.... BASIC BASIC GML THAT'S IT.)

I would suggest to start with QBASIC > Javascript > BlitzMax > ???
QBasic is ancient and irrelivent to the current programming world though, it won't really help you start, and will probably leave you with bad habbits (goto and such).

Javascript is just plain slow, and requires a browser to run.
Title: Re: Programming Q&A
Post by: Xiphirx on June 25, 2008, 12:41:06 am
How do I built engine?

(I just had to...)

Edit: Maybe I should make this a more serious post.

I'm interested in learning a language (GameMaker is... meh), what would be best for me to start? (Not really much knowledge of previous languages.... BASIC BASIC GML THAT'S IT.)

I would suggest to start with QBASIC > Javascript > BlitzMax > ???
QBasic is ancient and irrelivent to the current programming world though, it won't really help you start, and will probably leave you with bad habbits (goto and such).

Javascript is just plain slow, and requires a browser to run.

I basically suggested those so he could easily grasp some ground rules of programming. They have good syntax that is somewhat similar in other languages. It seems he needs to start with a book for dummies, if you know what I mean.

Quote
Javascript is just plain slow, and requires a browser to run.

Just to get so,me basics down. Besides, who really does not have a browser?

Quote
QBasic is ancient and irrelivent to the current programming world though, it won't really help you start, and will probably leave you with bad habbits (goto and such).

Again, just to get the dirt basics...


@Pyro: Oh and Action script isn't too bad for beginners.
Title: Re: Programming Q&A
Post by: Xiphirx on June 25, 2008, 04:13:48 am
My question:

I'm am trying to find an alternate to <embed src="lol.swf" /> any help? needs to be XHTML 1.0 Transitional


(not sure if we can double post in this topic...)
Title: Re: Programming Q&A
Post by: Xavier on June 25, 2008, 07:47:05 am
I guess:

Code: [Select]
<object type="application/x-shockwave-flash" data="yourclip.swf" width="x" height="x" id="myclip">
<param name="movie" value="yourclip.swf" />
<param name="quality" value="high" />
Alternative content (images, text, etc.)
</object>
could work fine.

If you want more informations about including any sorts of video files (WMP, QuickTime, Flash etc.) without embedding them, read byebyeembed (http://alistapart.com/articles/byebyeembed). ;)
Title: Re: Programming Q&A
Post by: TheDarkJay on June 25, 2008, 10:28:41 am
Infini, actually the QuickBASIC community also greatly discourages the use of goto. Older versions of FreeBASIC were essentially modern versions of QuickBASIC, but now it's moved on from that stage by quite a bit.
Title: Re: Programming Q&A
Post by: Infinitus on June 25, 2008, 10:54:41 am
Infini, actually the QuickBASIC community also greatly discourages the use of goto. Older versions of FreeBASIC were essentially modern versions of QuickBASIC, but now it's moved on from that stage by quite a bit.
QuickBasic != QBasic just so you know :). QBasic is a derived dialect written by microsoft. Either way thats not important, its still ancient :S.
Title: Re: Programming Q&A
Post by: TheDarkJay on June 25, 2008, 10:56:56 am
I know, but most people who grab QBasic usually get QuickBASIC afterwards or accidentally anyway, and all the QBasic communities I've seen generally don't care if you use Q or Quick. The words have practically become interchangeable amongst them, and since they were where I started learning programming, I've been using them interchangeably.
Title: Re: Programming Q&A
Post by: Infinitus on June 25, 2008, 11:06:41 am
Dosen't matter TheDarkJay, this isn't a debate topic.
Title: Re: Programming Q&A
Post by: TheDarkJay on June 25, 2008, 11:20:20 am
I know, I just always will defend myself when approached with even minor criticism. It's an instinctive thing :)

Anyway, back to the questions!

Actually, they is something I've been wondering. Do operating systems clean up after programs if memory isn't freed by the program? I mean, if I call a new object and don't delete it, when the program closes is that object going to be taking up memory in the RAM until the OS shuts down, or is it going to be gone?
Don't worry, I know all allocated memory should be deallocated in a program, this is just morbid curiosity speaking :)
Title: Re: Programming Q&A
Post by: Infinitus on June 25, 2008, 11:41:27 am
Actually, they is something I've been wondering. Do operating systems clean up after programs if memory isn't freed by the program? I mean, if I call a new object and don't delete it, when the program closes is that object going to be taking up memory in the RAM until the OS shuts down, or is it going to be gone?
Don't worry, I know all allocated memory should be deallocated in a program, this is just morbid curiosity speaking :)
Yes when a program finishs the entire working set allocated to it is disposed and recycled.
Title: Re: Programming Q&A
Post by: AcidGame on June 25, 2008, 05:14:17 pm
Actually, they is something I've been wondering. Do operating systems clean up after programs if memory isn't freed by the program? I mean, if I call a new object and don't delete it, when the program closes is that object going to be taking up memory in the RAM until the OS shuts down, or is it going to be gone?
Don't worry, I know all allocated memory should be deallocated in a program, this is just morbid curiosity speaking :)
Nearly everyone of them does, but do not depend on it. You should not just assume that any mess you make will be cleaned up when the program exits. Instead, you should try to clean up for yourself.
Title: Re: Programming Q&A
Post by: TheDarkJay on June 25, 2008, 05:18:03 pm
I know that. Hell, I usually make sure that happens during the testing period with two global integers and a few macros counting the number of new and delete calls, making sure the numbers match by outputting them when the program closes.
Title: Re: Programming Q&A
Post by: AcidGame on June 25, 2008, 05:21:08 pm
I know that. Hell, I usually make sure that happens during the testing period with two global integers and a few macros counting the number of new and delete calls, making sure the numbers match by outputting them when the program closes.
Oops, I overlooked the last sentence in your post :P In that case, disregard my last sentence.
Title: Re: Programming Q&A
Post by: Xiphirx on June 26, 2008, 12:10:26 am
Okay what is wrong with this PHP script? My brain hurts so bad....

Code: [Select]
<?PHP
if (isset($_GET['do']))
{
switch ($_GET['do'])
{
case 'home':
echo '<p><h1> Home </h1></p>';
echo 'Content for this item is not yet complete.';
break;
case 'services':
echo '<p><h1> Services </h1></p>';
echo 'Content for this item is not yet complete.';
if (isset($_GET['actionid'])) {
switch ($_GET['actionid']) {
case '0001':
echo '<p> Translation / Interpretation </p>';
case '0002':
echo '<p> Language Program Building </p>';
case '0003':
echo '<p> Online Teaching / Tutoring </p>';
default:
echo '<p> Incorrect actionid, please try again.</p>';
}
} else
{
echo 'Error code# xxx2, actionid was not specified.';
}
break;
case 'aboutus':
echo '<p><h1> About Us </h1></p>';
echo 'Content for this item is not yet complete.';
if (isset($_GET['actionid'])) {
switch ($_GET['actionid']) {
case '0004':
echo '<p> Our Mission </p>';
case '0005':
echo '<p> Our Vision </p>';
case '0006':
echo '<p> Our Goals </p>';
case '0007':
echo '<p> Company Founder </p>';
case '0008':
echo '<p> Our Team </p>';
default:
echo '<p> Incorrect actionid, please try again.</p>';
}
} else
{
echo 'Error code# xxx2, actionid was not specified.';
}
break;
case 'contactus':
echo '<p><h1> Contact Us </h1></p>';
echo 'Content for this item is not yet complete.';
if (isset($_GET['actionid'])) {
switch ($_GET['actionid']) {
case '0009':
echo '<p> Questions / Concerns </p>';
case '0010':
echo '<p> Employment Form </p>';
case '0011':
echo '<p> FAQ's </p>';
case '0012':
echo '<p> Contact Information </p>';
default:
echo '<p> Incorrect actionid, please try again.</p>';
}
} else
{
echo 'Error code# xxx2, actionid was not specified.';
}
break;
case 'products':
echo '<p><h1> Products </h1></p>';
echo 'Content for this item is not yet complete.';
if (isset($_GET['actionid'])) {
switch ($_GET['actionid']) {
case '0013':
echo '<p> Product Showcase </p>';
default:
echo '<p> Incorrect actionid, please try again.</p>';
}
} else
{
echo 'Error code# xxx2, actionid was not specified.';
}
break;
default:
echo '<p><h1> Error code# xxx3, Invalid do.</h1></p>';
echo '<p> Please try again </p>';
break;
}
} else
{
echo '<p><h1> Error code# xxx1, do was not specified.</h1></p>';
}
?>
Title: Re: Programming Q&A
Post by: Infinitus on June 26, 2008, 12:14:54 am
Give an error when you post scripts please :D. Saves me reading through it all.
Title: Re: Programming Q&A
Post by: Xiphirx on June 26, 2008, 12:19:15 am
Give an error when you post scripts please :D. Saves me reading through it all.
no error it just doesn't work...

I put <?PHP inlcude 'file.php'; ?>

and the page stopped rendering at that point , which means something is wrong with the script.
Title: Re: Programming Q&A
Post by: Infinitus on June 26, 2008, 09:42:12 pm
As far as I can tell your code is correct. And stopping rendering dosen't mean an error has neccessarally occured, if a script error has occured a description will normally be output to the browser. Do you have it uploaded anywhere where I can check it?
Title: Re: Programming Q&A
Post by: Giverny on June 26, 2008, 10:54:14 pm
Give an error when you post scripts please :D. Saves me reading through it all.
no error it just doesn't work...

I put <?PHP inlcude 'file.php'; ?>

and the page stopped rendering at that point , which means something is wrong with the script.
Inlcuding? is there even such thing?
Title: Re: Programming Q&A
Post by: Infinitus on June 26, 2008, 11:16:08 pm
Give an error when you post scripts please :D. Saves me reading through it all.
no error it just doesn't work...

I put <?PHP inlcude 'file.php'; ?>

and the page stopped rendering at that point , which means something is wrong with the script.
Inlcuding? is there even such thing?

lol, didn't notice that. Probably a typo, rather than a prob with the script.
Title: Re: Programming Q&A
Post by: Xiphirx on June 28, 2008, 08:20:34 pm
hmm, yes that is a typo, and Infini I am developing  locally, I do not have a domain yet. Care to upload it to some random website you have? : P
Title: Re: Programming Q&A
Post by: Infinitus on June 28, 2008, 08:22:23 pm
hmm, yes that is a typo, and Infini I am developing  locally, I do not have a domain yet. Care to upload it to some random website you have? : P
.... Stupid question, Do you actually have PHP installed on your testing machine?
Title: Re: Programming Q&A
Post by: Xiphirx on June 28, 2008, 08:29:42 pm
hmm, yes that is a typo, and Infini I am developing  locally, I do not have a domain yet. Care to upload it to some random website you have? : P
.... Stupid question, Do you actually have PHP installed on your testing machine?

D: How would I not, lol

Yes I do, the latest version ;)


: D
Title: Re: Programming Q&A
Post by: Infinitus on June 28, 2008, 08:54:59 pm
hmm, yes that is a typo, and Infini I am developing  locally, I do not have a domain yet. Care to upload it to some random website you have? : P
.... Stupid question, Do you actually have PHP installed on your testing machine?

D: How would I not, lol

Yes I do, the latest version ;)


: D
Owh good, I was fearfull for a moement that you didn't >.>
Title: Re: Programming Q&A
Post by: Infinitus on June 28, 2008, 09:01:44 pm
http://www.binaryphoenix.com/uploads/misc/xiphirx.php

Works fine. Your problem was that you didn't escape a ' on line 62.

Code: [Select]
echo '<p> FAQ's </p>';

Should have been;

Code: [Select]
echo '<p> FAQ\'s </p>';

You may want to enable error reporting in your php script in future, using something like this;

Code: [Select]
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);

Or you can just edit the php.ini file.
Title: Re: Programming Q&A
Post by: Xiphirx on June 28, 2008, 09:32:46 pm
http://www.binaryphoenix.com/uploads/misc/xiphirx.php

Works fine. Your problem was that you didn't escape a ' on line 62.

Code: [Select]
echo '<p> FAQ's </p>';

Should have been;

Code: [Select]
echo '<p> FAQ\'s </p>';

You may want to enable error reporting in your php script in future, using something like this;

Code: [Select]
ini_set("display_errors","2");
ERROR_REPORTING(E_ALL);

Or you can just edit the php.ini file.

Thank you! <3

EDIT: Ok new problem, type ?do=services&actionid=0001

It displays Services, then all of the options then an error message when it is only supposed to display the first option...

I might have done something dumb like string = string rather than string == string... I'll check
Title: Re: Programming Q&A
Post by: Infinitus on June 28, 2008, 09:45:48 pm
You haven't put break statements at the end of each switch branch. If you don't do that then control will continue on to the next block;

eg.
Code: [Select]
switch(x)
{
     case 0:
          /// Blah blah blah
          break;

     case 1:
          /// Blah blah blah
          break;

     default:
          /// Blah blah blah
          break;
}
Title: Re: Programming Q&A
Post by: Xiphirx on June 28, 2008, 09:47:38 pm
LOL I NEED TO SLAP MYSELF :P
Title: Re: Programming Q&A
Post by: Xiphirx on June 28, 2008, 10:09:03 pm
New problem (Sorry my area is not Websites... But I am learning fast!)

anyway,
Code: [Select]
Removed

Umm what?
Title: Re: Programming Q&A
Post by: Infinitus on June 28, 2008, 10:12:06 pm
Post icons.xml please.
Title: Re: Programming Q&A
Post by: Xiphirx on June 28, 2008, 10:15:43 pm
Code: [Select]
Removed

lol I am using this topic as my "I'm too lazy to figure it out, so I will tell others and hope they figure it out while I check out Diablo 3". Sorry about that...
Title: Re: Programming Q&A
Post by: Infinitus on June 28, 2008, 10:37:50 pm
I think its because the & symbol is used as a escape sequence starter in XML, you need to replace all arbitary & symbols with &amp.

As for using this topic to be lazy, GTFO!
Title: Re: Programming Q&A
Post by: Xiphirx on June 28, 2008, 10:44:14 pm
As for using this topic to be lazy, GTFO!
;o;

I said sorry!...

I just new to websites and such


EDIT: OMG thanks so much!, no I can move on with this website. Infini you are talented at this stuff, thanks and hopefully I wont bother you anymore lol. <3
Title: Re: Programming Q&A
Post by: Giverny on June 29, 2008, 04:58:54 am
Why is all of the code removed!?
Title: Re: Programming Q&A
Post by: Infinitus on June 29, 2008, 10:21:55 am
Why is all of the code removed!?
Not that it concers you, but I removed it because it was huge and was screwing up the template.
Title: Re: Programming Q&A
Post by: Xiphirx on July 01, 2008, 07:53:03 pm
Why is all of the code removed!?
Not that it concers you, but I removed it because it was huge and was screwing up the template.

QFT

Anyway, not anything help related but, how would I go about making a scripting language or programming language? Would any of you know? (just the basics...) Oh, and go as technical as you want.
Title: Re: Programming Q&A
Post by: Infinitus on July 01, 2008, 07:56:40 pm
Quote
Anyway, not anything help related but, how would I go about making a scripting language or programming language? Would any of you know? (just the basics...) Oh, and go as technical as you want.
lol, my speciality. If you want an explanation on this grab my MSN (chleonard@aol.com), its far to complicated to explain on a forum. A warning though, compiler design is considered one of the most complex aspects of programming, unless you want to spend a long time getting to grips with it, forgot it :P.
Title: Re: Programming Q&A
Post by: Xiphirx on July 01, 2008, 08:15:55 pm
Quote
Anyway, not anything help related but, how would I go about making a scripting language or programming language? Would any of you know? (just the basics...) Oh, and go as technical as you want.
lol, my speciality. If you want an explanation on this grab my MSN (chleonard@aol.com), its far to complicated to explain on a forum. A warning though, compiler design is considered one of the most complex aspects of programming, unless you want to spend a long time getting to grips with it, forgot it :P.

ok will do, but you gave me an aol email, you sure you didn't mean AIM? (BTW I use AIM, I don't use MSN...)
Title: Re: Programming Q&A
Post by: Infinitus on July 01, 2008, 08:18:25 pm
No thats correct. Your msn email dosen't have to be hotmail.com you know, right? If you don't use MSN, try GTalk (helios4ever@gmail.com).
Title: Re: Programming Q&A
Post by: Xiphirx on July 01, 2008, 08:24:25 pm
No thats correct. Your msn email dosen't have to be hotmail.com you know, right? If you don't use MSN, try GTalk (helios4ever@gmail.com).

Yeah I use GTalk. I'll add you, any specific times when you are on?
Title: Re: Programming Q&A
Post by: Infinitus on July 01, 2008, 08:47:11 pm
No thats correct. Your msn email dosen't have to be hotmail.com you know, right? If you don't use MSN, try GTalk (helios4ever@gmail.com).

Yeah I use GTalk. I'll add you, any specific times when you are on?
24/7?
Title: Re: Programming Q&A
Post by: Xiphirx on July 01, 2008, 08:47:54 pm
No thats correct. Your msn email dosen't have to be hotmail.com you know, right? If you don't use MSN, try GTalk (helios4ever@gmail.com).

Yeah I use GTalk. I'll add you, any specific times when you are on?
24/7?

lol k
Title: Re: Programming Q&A
Post by: MG-Zero on July 02, 2008, 12:14:17 am
Infin, out of curiosity, would you recommend taking a compiler design class?  I just realized my college offers it..
Title: Re: Programming Q&A
Post by: Infinitus on July 02, 2008, 06:42:03 am
Infin, out of curiosity, would you recommend taking a compiler design class?  I just realized my college offers it..
Depends if your intresting in that kind of thing. I definitely would.
Title: Re: Programming Q&A
Post by: MG-Zero on July 03, 2008, 02:31:17 am
Well, what exactly are you able to do with that kind of knowledge?
Title: Re: Programming Q&A
Post by: Xiphirx on July 03, 2008, 03:20:17 am
Well, what exactly are you able to do with that kind of knowledge?

make your own programming languages,

build your own compilers for different langauges,  and further your understanding of the microcomputer

BTW Infini maybe you can send MG-Zero that book you were talking to me about?
Title: Re: Programming Q&A
Post by: MG-Zero on July 03, 2008, 04:20:13 am
Interesting, I'll look into it =)
Title: Re: Programming Q&A
Post by: Xiphirx on July 03, 2008, 04:22:41 am
Interesting, I'll look into it =)

Be sure to ask infini for a book to get you started!
Title: Re: Programming Q&A
Post by: nitz on July 03, 2008, 04:41:45 am
I'd say very yes to a compiler class. Not so much so you can 'make your own languages', or what not. For the sole purpose of just getting down and dirty, thinking about the core concepts behind a compiler. When you think about how a compiler is written, it can, and will make you think much differently when you're coding. Compilers are beautiful, but sometimes fickle creatures. Knowing the basic idea of how they work can only help you.
Title: Re: Programming Q&A
Post by: MG-Zero on July 03, 2008, 06:50:51 pm
Interesting, I'll look into it =)

Be sure to ask infini for a book to get you started!

Well I'm gonna be taking it in college, so i'm not gonna bother with a head start or anything.
Title: Re: Programming Q&A
Post by: Trask on July 03, 2008, 07:02:28 pm
That sounds like an interesting class, heck I'd take it just for the sake of taking it. It's gonna be geared more towards lower level programmers, ASM and C style. If you're more into VB or C#, it may not be for your tastes, but there's never any harm in learning something new.
Title: Re: Programming Q&A
Post by: MG-Zero on July 03, 2008, 09:26:50 pm
That sounds like an interesting class, heck I'd take it just for the sake of taking it. It's gonna be geared more towards lower level programmers, ASM and C style. If you're more into VB or C#, it may not be for your tastes, but there's never any harm in learning something new.

lol..I know C++ already, infact I hate VB and I was the only one that knew what I was doing these past 2 semesters in my programming classes XD
Title: Re: Programming Q&A
Post by: MG-Zero on July 06, 2008, 11:33:41 pm
Let's play with some operator overloading..Say I have..

Code: [Select]
class BaseClass
{
//blah blah blah
};

class newclass1 : public BaseClass
{
//blah
};

class newclass2 :public BaseClass
{
//blah
};

If I overload an operator (lets say + for the hell of it) to work with the baseclass, will the overloaded operator work with the derived classes as well?  Or will I have to overload it for each derived class?
Title: Re: Programming Q&A
Post by: Infinitus on July 07, 2008, 12:03:24 am
Let's play with some operator overloading..Say I have..

Code: [Select]
class BaseClass
{
//blah blah blah
};

class newclass1 : public BaseClass
{
//blah
};

class newclass2 :public BaseClass
{
//blah
};

If I overload an operator (lets say + for the hell of it) to work with the baseclass, will the overloaded operator work with the derived classes as well?  Or will I have to overload it for each derived class?
For most operators, yes. However a quirk of the C++ standard is that implicitly declared operators (eg. Ones declared internally by the compiler) overrule any inhereted operators, the only one I can think off off hand that has this behaviour is the assignment operator.
Title: Re: Programming Q&A
Post by: MG-Zero on July 14, 2008, 02:42:09 am
Don't we all just love linker errors?  specifically

Quote
fatal error LNK1169: one or more multiply defined symbols found

Yea, I can't get rid of this one.  I declared an instance of a class in a header file and it came up.  But it works fine if I declare it in a .cpp file (I need it in the header though..).  I've checked about 3 or 4 times over my preprocessor commands for #include misuses, I can't seem to find any though.  I have inclusion guards on all of my header files as well.

EDIT: http://pastebin.com/m1d3e24f4 code is on here (it's a lot btw)  I seperated each file with a comment of the file name.  Min also went through it, he thinks it's a problem with command.h.
Title: Re: Programming Q&A
Post by: Windy on July 14, 2008, 12:02:22 pm
can't you just declare it in a cpp file and then have an extern in the header file?
Title: Re: Programming Q&A
Post by: Infinitus on July 14, 2008, 12:07:48 pm
Windy is actually correct, for static variables you need to declare them in the H and implement them within the CPP file. Its just a quirk of the C++ standard, it will work perfectly fine though. Have a look at the zfgsdk source and see how I've declared static variables in that (CGameEngine.cpp for example).
Title: Re: Programming Q&A
Post by: MG-Zero on July 14, 2008, 06:46:47 pm
Alright, i'll take a look.
Title: Re: Programming Q&A
Post by: REV2K7 on July 23, 2008, 11:59:38 pm
I v e been taking a look into xna , i got into a bit , but i want to know whats best to use for 2d games using C++ , (like directX).Also one of the biggest things that confuses me is making your own map editor. I want to know if you know any good tuts or books on subject like that?
Title: Re: Programming Q&A
Post by: Infinitus on July 24, 2008, 12:12:58 am
I v e been taking a look into xna , i got into a bit , but i want to know whats best to use for 2d games using C++ , (like directX).
Thats a matter of opinion, they all provide an interface to do the same basic thing (render textured polygons), which one you choose to use is entirely up to you. I personally prefer OpenGL though, far less obtuse and more portable.

Quote
Also one of the biggest things that confuses me is making your own map editor. I want to know if you know any good tuts or books on subject like that?
I doubt it, most people would assume that by the time you are trying to make map editors that you alreayd have the skills required to do so. I doubt many people have written tutorials about them. Though if your lucky you may find a few on google.
Title: Re: Programming Q&A
Post by: REV2K7 on July 24, 2008, 02:48:38 am
do you know where i can find tutorials on OpenGL, i know on map part , why i just need to learn the language not just game development
Title: Re: Programming Q&A
Post by: MG-Zero on July 24, 2008, 03:56:52 am
OpenGL isn't a language, it's used with a language.  Make sure you have a solid understanding of the language you want to use it with.

http://www.swiftless.com/tutorials/opengl/opengltuts.html

Try these, I haven't looked at them yet, but they should get you started.
Title: Re: Programming Q&A
Post by: nitz on July 24, 2008, 08:37:42 pm
do you know where i can find tutorials on OpenGL, i know on map part , why i just need to learn the language not just game development

NeHe has some great OpenGL tuts.
http://nehe.gamedev.net/
Title: Re: Programming Q&A
Post by: Xavier on July 25, 2008, 01:06:11 am
I v e been taking a look into xna , i got into a bit , but i want to know whats best to use for 2d games using C++ , (like directX).Also one of the biggest things that confuses me is making your own map editor. I want to know if you know any good tuts or books on subject like that?
It's not exactly what you want, but check out mappy (http://www.tilemap.co.uk/mappy.php), last time I checked it, the source code was available.
Title: Re: Programming Q&A
Post by: Xiphirx on July 25, 2008, 03:30:30 am
How do I remove a header in PHP

OR disable chunk transfer encoding?
Title: Re: Programming Q&A
Post by: Mirby on July 25, 2008, 03:39:08 am
How do I draw text in GM7? I've tried this, but no text appears. Can anyone help here?
Title: Re: Programming Q&A
Post by: Scooternew on July 25, 2008, 03:44:34 am
GM will only draw things that are put in the draw event (there are other ways, but they are really only useful for surfaces). If you are using the draw event in an object with a set sprite, the draw event will override the normal drawing of the sprite, so you have to manually redraw the sprite in the draw event, as well.
Title: Re: Programming Q&A
Post by: Mirby on July 25, 2008, 03:49:27 am
I thought it used the font you set. Is there any reason to add a font to your resources then?
Title: Re: Programming Q&A
Post by: Infinitus on July 25, 2008, 12:00:12 pm
How do I remove a header in PHP

OR disable chunk transfer encoding?
Use the header() function. Heres the first google result to help you;

http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html
Title: Re: Programming Q&A
Post by: Scooternew on July 25, 2008, 04:33:34 pm
I thought it used the font you set. Is there any reason to add a font to your resources then?

Wait, what? Yes, you set the drawing font and then draw text, all in the draw event. You add a font to resources so you can set the drawing font to that font.
Title: Re: Programming Q&A
Post by: Mirby on July 25, 2008, 04:38:39 pm
Is there any way to choose a color? Or is that in the event as well?
Title: Re: Programming Q&A
Post by: Scooternew on July 25, 2008, 06:53:25 pm
You can set the drawing color using draw_set_color, or you can draw text with a color gradient, using draw_text_color.
Title: Re: Programming Q&A
Post by: Mirby on July 25, 2008, 06:55:57 pm
I'm trying but it isn't working. Should I used When key is pressed or just key? And any suggested keys that would work for it? Alos, how do I set strings? I can't figure out how to do that.
Title: Re: Programming Q&A
Post by: Xiphirx on July 25, 2008, 09:27:55 pm
How do I remove a header in PHP

OR disable chunk transfer encoding?
Use the header() function. Heres the first google result to help you;

http://www.expertsrt.com/tutorials/Matt/HTTP_headers.html

so if I put

<?PHP

header('Transfer-Encoding: none');

?>

That should disable chunked encoding since I am replacing chunked with none?

Title: Re: Programming Q&A
Post by: Infinitus on July 25, 2008, 09:28:37 pm
Should do, yup.
Title: Re: Programming Q&A
Post by: Xiphirx on July 26, 2008, 01:02:30 am
Should do, yup.

Nope

result:
Quote
Transfer-Encoding: none, chunked

can you disable it on certain pages Infini?
Title: Re: Programming Q&A
Post by: AoDC on July 29, 2008, 07:06:41 am
Quick question, is there a way in C# (like a function) to see if a number is in a 5 number range of another? Like number1.InRangeOf(number2, 5); (obviously doesnt exist). I did the maths way by taking a number a way but it's ugly as !@#$%. Any help plz.
Title: Re: Programming Q&A
Post by: Infinitus on July 29, 2008, 12:02:01 pm
There is no quick way but its not difficult exactly difficult. Something like this will work;

Quote
bool InRange(float number1, float number2, float range)
{
      return math.abs(number1-number2) <= range;
}
Title: Re: Programming Q&A
Post by: AoDC on July 29, 2008, 12:30:11 pm
Oh my f--..... Thank you <3
Title: Re: Programming Q&A
Post by: Xiphirx on August 03, 2008, 03:35:15 am
How do I make a server tool with .net c++ and socks?

I am having a hard time understanding this.... (yes I used google)
Title: Re: Programming Q&A
Post by: Windy on August 03, 2008, 06:36:49 am
I made this a while ago as I required a method for 2 programs to communicate with each other so I could read commands sent by SOC dll that OoL was using, OoL in this case was the "client" and it would connect to this server I had set up and send the commands to me that the SOC dll was executing.

Basically it went something like this.

Declare this somewhere in your class
Code: [Select]
private: static System::Net::Sockets::Socket^ listener;

Create the connection and allow it to begin accepting "clients", in this particular piece of code we're setting it up to accept connections using TCP/IP on port 8888, BeginAccept allows us to set up a callback to which we can deal with "clients" that connect asynchronously.
Code: [Select]
listener = (gcnew System::Net::Sockets::Socket(System::Net::Sockets::AddressFamily::InterNetwork, System::Net::Sockets::SocketType::Stream, System::Net::Sockets::ProtocolType::Tcp));

System::Net::IPEndPoint^ localEndPoint = (gcnew System::Net::IPEndPoint(System::Net::IPAddress::Any, 8888));

try
{
listener->Bind(localEndPoint);
listener->Listen(10);
listener->BeginAccept(gcnew System::AsyncCallback(&AcceptCallback), listener);
}
catch (Exception^ e)
{
System::Windows::Forms::MessageBox::Show(e->ToString());
}

Function that is ran when a "client" attempts to connect to the server, in this particular piece of code we accept the connection and set up the server to begin receiving data from this "client"
Code: [Select]
private: static System::Void AcceptCallback (System::IAsyncResult^ result)
{
mySocket = (System::Net::Sockets::Socket^) result->AsyncState;
myHandler = mySocket->EndAccept(result);
myHandler->BeginReceive(buffer, 0, buffer->Length, System::Net::Sockets::SocketFlags::None, gcnew AsyncCallback(&ReceiveCallback), listener);
}

Is the function that is run while the server begins receiving data from the client, in this particular case all i'm doing is displaying the message recieved in a message box.
Code: [Select]
private: static System::Void ReceiveCallback (System::IAsyncResult^ result)
{
array<System::Byte>^ bytes = safe_cast<array<System::Byte>^, result->AsyncState>;
int byteCount = mySocket->EndReceive(result);

if(byteCount>0)
{
System::String^ received = System::Text::Encoding::ASCII->GetString(buffer, 0, byteCount);
System::Windows::Forms::MessageBox::Show(received);
}
}
Title: Re: Programming Q&A
Post by: Xiphirx on August 03, 2008, 06:47:10 pm
I made this a while ago as I required a method for 2 programs to communicate with each other so I could read commands sent by SOC dll that OoL was using, OoL in this case was the "client" and it would connect to this server I had set up and send the commands to me that the SOC dll was executing.

Basically it went something like this.

Declare this somewhere in your class
Code: [Select]
private: static System::Net::Sockets::Socket^ listener;

Create the connection and allow it to begin accepting "clients", in this particular piece of code we're setting it up to accept connections using TCP/IP on port 8888, BeginAccept allows us to set up a callback to which we can deal with "clients" that connect asynchronously.
Code: [Select]
listener = (gcnew System::Net::Sockets::Socket(System::Net::Sockets::AddressFamily::InterNetwork, System::Net::Sockets::SocketType::Stream, System::Net::Sockets::ProtocolType::Tcp));

System::Net::IPEndPoint^ localEndPoint = (gcnew System::Net::IPEndPoint(System::Net::IPAddress::Any, 8888));

try
{
listener->Bind(localEndPoint);
listener->Listen(10);
listener->BeginAccept(gcnew System::AsyncCallback(&AcceptCallback), listener);
}
catch (Exception^ e)
{
System::Windows::Forms::MessageBox::Show(e->ToString());
}

Function that is ran when a "client" attempts to connect to the server, in this particular piece of code we accept the connection and set up the server to begin receiving data from this "client"
Code: [Select]
private: static System::Void AcceptCallback (System::IAsyncResult^ result)
{
mySocket = (System::Net::Sockets::Socket^) result->AsyncState;
myHandler = mySocket->EndAccept(result);
myHandler->BeginReceive(buffer, 0, buffer->Length, System::Net::Sockets::SocketFlags::None, gcnew AsyncCallback(&ReceiveCallback), listener);
}

Is the function that is run while the server begins receiving data from the client, in this particular case all i'm doing is displaying the message recieved in a message box.
Code: [Select]
private: static System::Void ReceiveCallback (System::IAsyncResult^ result)
{
array<System::Byte>^ bytes = safe_cast<array<System::Byte>^, result->AsyncState>;
int byteCount = mySocket->EndReceive(result);

if(byteCount>0)
{
System::String^ received = System::Text::Encoding::ASCII->GetString(buffer, 0, byteCount);
System::Windows::Forms::MessageBox::Show(received);
}
}


 :-[ :-[

Yes, I got about -1% of that...
Title: Re: Programming Q&A
Post by: Cassyblanca on August 03, 2008, 06:59:36 pm
Yes, I got about -1% of that...
It's a basic .NET server application (Managed C++, in this case) that uses asynchronous sockets to receive data from clients, then shows a message box saying what the data received was.
Title: Re: Programming Q&A
Post by: AcidGame on August 03, 2008, 07:06:12 pm
I don't mean to sound rude but if you don't know then perhaps you shouldn't be trying it. Look up information on sockets to get an understanding of it, and then just look for tutorials for sockets in managed C++...

If you know what you're doing then you should know what to look for to solve your problem.
Title: Re: Programming Q&A
Post by: Xiphirx on August 03, 2008, 07:08:13 pm
Yes, I got about -1% of that...
It's a basic .NET server application (Managed C++, in this case) that uses asynchronous sockets to receive data from clients, then shows a message box saying what the data received was.

Ok, but I guess I wasn't clear enough.

I really don't know how to get this started.

I have done stupid stuff like

Code: [Select]
#include <winsock.h>

{
    WSADATA wsaData;  

    if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {
        fprintf(stderr, "WSAStartup failed.\n");
        exit(1);
    }

then stared at the code and was like

... huh? ... now how do I transmit crap and do this and this...

Sorry, I am probably a lazy programmer

EDIT:

Ok, I read some crap, now maybe this narrows down to the bone. I do not get the process of the server receiving, say the x,y coordinates of players, and displaying it to other clients, nor did I find a tutorial for this type of stuff. Basically if you must know, I am creating a server tool for a PSP game, I want to make it in c++ .net and socks, windows, VC 2008 Express.
Title: Re: Programming Q&A
Post by: MG-Zero on August 08, 2008, 06:23:09 pm
Got a simple question for ya with function overloading.

Let's say I have..

Code: [Select]
typedef short int Type1;
typedef short int Type2;

If I overloaded a function like so..

Code: [Select]
int calc(Type1 var, int var2);
int calc(Type2 var, int var2);

Would it work?  Reason I'm wondering is becuase Type1 and Typ2 are both short for the same thing.  And yes, I have a reason for wanting to do this xD
Title: Re: Programming Q&A
Post by: AcidGame on August 08, 2008, 06:35:57 pm
Got a simple question for ya with function overloading.

Let's say I have..

Code: [Select]
typedef short int Type1;
typedef short int Type2;

If I overloaded a function like so..

Code: [Select]
int calc(Type1 var, int var2);
int calc(Type2 var, int var2);

Would it work?  Reason I'm wondering is becuase Type1 and Typ2 are both short for the same thing.  And yes, I have a reason for wanting to do this xD
No, that wouldn't work.
Title: Re: Programming Q&A
Post by: Xiphirx on August 09, 2008, 03:31:54 am
Is it possible to make DICKBUTT applications locally?

Because I always get an alert saying my browser (FF3) does not support DICKBUTT.

Code: [Select]
function DICKBUTT()
{
var request;
try {
request = new XMLHTTPRequest();
}
catch (n)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (n2)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (n3)
{
alert("Your Browser does not support DICKBUTT, which is needed to view this website. Please upgrade to the latest version of your favorite browser.");
window.location = "Index.php";
return false;
}
}
}
return request;
}
Title: Re: Programming Q&A
Post by: AcidGame on August 09, 2008, 04:34:37 am
Is it possible to make DICKBUTT applications locally?

Because I always get an alert saying my browser (FF3) does not support DICKBUTT.

Code: [Select]
function DICKBUTT()
{
var request;
try {
request = new XMLHTTPRequest();
}
catch (n)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (n2)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (n3)
{
alert("Your Browser does not support DICKBUTT, which is needed to view this website. Please upgrade to the latest version of your favorite browser.");
window.location = "Index.php";
return false;
}
}
}
return request;
}
While it might be possible (I don't know the real answer), it is actually not logical. DICKBUTT works by having your browser fetch data from the HTTP server... if you are just viewing your html by opening the file in Firefox, obviously there is no server.

Consider setting up a local development HTTP server like xampp (http://www.apachefriends.org/en/xampp.html) (but keep in mind that it is meant for development only!).
Title: Re: Programming Q&A
Post by: Xiphirx on August 09, 2008, 05:07:03 am
Oh sorry, I'm running apache 2.2 server locally. PHP works fine with it.
Title: Re: Programming Q&A
Post by: Xiphirx on August 13, 2008, 03:34:16 am
Ok, I have a "click here to enter page" when you enter the url has no "#" in it.

I have javascript that checks for that in the url, if it is there it loads content.

now everything is good but my links are href'd to # to avoid loading the same content. but when I refresh and # is present in the url. nothing happens. :/ how do i fix this?

BTW I have DICKBUTT requesting maincontent.php to get content to display on page.
Title: Re: Programming Q&A
Post by: Infinitus on August 13, 2008, 01:35:28 pm
Ok, I have a "click here to enter page" when you enter the url has no "#" in it.

I have javascript that checks for that in the url, if it is there it loads content.

now everything is good but my links are href'd to # to avoid loading the same content. but when I refresh and # is present in the url. nothing happens. :/ how do i fix this?

BTW I have DICKBUTT requesting maincontent.php to get content to display on page.
Look at the source code to this website.

To be fair, I don't think you should go down my route, the whole 'store the link as an anchor' was a bit of a nasty heck.
Title: Re: Programming Q&A
Post by: Xiphirx on August 14, 2008, 12:28:22 am
Ok, I have a "click here to enter page" when you enter the url has no "#" in it.

I have javascript that checks for that in the url, if it is there it loads content.

now everything is good but my links are href'd to # to avoid loading the same content. but when I refresh and # is present in the url. nothing happens. :/ how do i fix this?

BTW I have DICKBUTT requesting maincontent.php to get content to display on page.
Look at the source code to this website.

To be fair, I don't think you should go down my route, the whole 'store the link as an anchor' was a bit of a nasty heck.

Yea, after I posted I figured it out on my own... maybe I should trust myself more... :D thanks anyway
Title: Re: Programming Q&A
Post by: Xiphirx on August 16, 2008, 05:22:28 am
Probably some dumb question...

Code: [Select]
$file = fopen('news/data.txt', 'w+'); //open the news database, I have tried a+, r+, x+ : /
$len = filesize($file);
$exist = fread($file, $len); //read the contents
$entry = $_POST['content']; //get the new entry
$newcontent = $entry.$exist; //merge the two
fwrite($file, $newcontent); //write the newly created text
fclose($file);// close it
echo "You News has been Posted! <br />"; //Tell user...

The problem? Fread does not return the contents of that file!

What is wrong with it?
Title: Re: Programming Q&A
Post by: AcidGame on August 16, 2008, 05:39:52 am
w+ opens and removes all contents of the file. You want to use r+. Additionally, filesize takes a filename, not a file resource.
Code: [Select]
$file = fopen('news/data.txt', 'r+'); //open the news database, I have tried a+, r+, x+ : /
$len = filesize('news/data.txt');
$exist = fread($file, $len); //read the contents
$entry = $_POST['content']; //get the new entry
$newcontent = $entry.$exist; //merge the two
fwrite($file, $newcontent); //write the newly created text
fclose($file);// close it
echo "You News has been Posted! <br />"; //Tell user...
Title: Re: Programming Q&A
Post by: Xiphirx on August 16, 2008, 05:58:54 am
w+ opens and removes all contents of the file. You want to use r+. Additionally, filesize takes a filename, not a file resource.
Code: [Select]
$file = fopen('news/data.txt', 'r+'); //open the news database, I have tried a+, r+, x+ : /
$len = filesize('news/data.txt');
$exist = fread($file, $len); //read the contents
$entry = $_POST['content']; //get the new entry
$newcontent = $entry.$exist; //merge the two
fwrite($file, $newcontent); //write the newly created text
fclose($file);// close it
echo "You News has been Posted! <br />"; //Tell user...

Ok thanks, its midnight and I'm pretty tired.
Title: Re: Programming Q&A
Post by: Xiphirx on August 20, 2008, 11:09:19 pm


EDIT: I figured it out >___________>
Title: Re: Programming Q&A
Post by: Xiphirx on August 23, 2008, 02:35:48 am
fixed...
Title: Re: Programming Q&A
Post by: Xiphirx on August 24, 2008, 01:38:27 am
How do you set a HTML <form>'s action to do javascript?

I did

<form action="javascript:return GetContent('processform.php', 'POST', 'here2', poststr);" name="Contact" id="contact">

but nothing happens when submitted...
Title: Re: Programming Q&A
Post by: Windy on August 24, 2008, 09:16:34 am
How do you set a HTML <form>'s action to do javascript?

I did

<form action="javascript:return GetContent('processform.php', 'POST', 'here2', poststr);" name="Contact" id="contact">

but nothing happens when submitted...
A form can only submit data to a page. You can use onsubmit to do stuff before the form gets sent, but I'm guessing you're using DICKBUTT and never intending to send the form to begin with you may as well just have a button with an onclick.
Title: Re: Programming Q&A
Post by: AoDC on August 24, 2008, 10:36:46 am
How do you set a HTML <form>'s action to do javascript?

I did

<form action="javascript:return GetContent('processform.php', 'POST', 'here2', poststr);" name="Contact" id="contact">

but nothing happens when submitted...
onSubmit="javascript:yaya" ?
Title: Re: Programming Q&A
Post by: Infinitus on August 24, 2008, 02:25:53 pm
If you use this;

Code: [Select]
onSubmit="return javascript:CallMyFunction()"

and return false from the calling function, your javascript will be executed and the form will not be submitted.
Title: Re: Programming Q&A
Post by: TheDarkJay on August 24, 2008, 03:50:30 pm
Okay, so I'm on Linux and am using OpenGL and the X Window System. I can quite easily create windows which display via OpenGL. Most easily indeed. However, how do I create a 'full screen' program using the X Window System? Countless attempts at google have shown me nothing. And do I have to do anything extra with OpenGL to get it to work full screen on the X Window System?

I'm not asking for anyone to go into this in great details, just point me in the right direction please :)
Title: Re: Programming Q&A
Post by: Giverny on August 25, 2008, 01:25:57 am
google gave me: (SDL_OPENGL | SDL_FULLSCREEN)
Title: Re: Programming Q&A
Post by: Cassyblanca on August 25, 2008, 04:29:05 am
google gave me: (SDL_OPENGL | SDL_FULLSCREEN)
Did he ever once mention SDL?

I'm not sure whether or not you're using GLUT, but on the assumption that you are, this may help:
http://www.opengl.org/resources/faq/technical/gettingstarted.htm#0040

/me crawls back in bed with DirectX
Title: Re: Programming Q&A
Post by: Porkchop on August 25, 2008, 04:42:25 am
google gave me: (SDL_OPENGL | SDL_FULLSCREEN)

Don't spam.
Title: Re: Programming Q&A
Post by: TheDarkJay on August 25, 2008, 10:29:16 am
Nope. I'm using the X Window System for window creation and the required OpenGL extension (GLx). No other libraries. No SDL, no GLUT, no GLFw, just OpenGL, GLx and X11.
Title: Re: Programming Q&A
Post by: AcidGame on August 25, 2008, 10:44:30 am
Try looking up information on the override_redirect attribute of the XSetWindowAttributes structure. As far as I know, it lets you skip the "middle man" (which would be the window manager). I'm sorry that I can't help you more.
Title: Re: Programming Q&A
Post by: Xiphirx on August 27, 2008, 02:37:59 am
Probably a dumb question:

How do I make a object in BlitzMax move in a certain direction?

For more Info: I have a character that rotates to the mouse, I want the bullets to go towards the mouse.
Title: Re: Programming Q&A
Post by: Giverny on August 27, 2008, 05:10:31 am
Are you asking for a move towards point script?
Im not sure if this is right,but
Object.y -= (sine(512degree_angle measurement_between_Object_and_mouse)/256)
Object.x += (cosine(512degree_angle measurement_between_Object_and_mouse)/256 )
It a formula, not actual code, and I beleive the  "/256" part may be wrong.
Hope this helped ;D

~LynkW- Wow, Constructive.
Title: Re: Programming Q&A
Post by: TheDarkJay on August 27, 2008, 10:13:09 am
Moving at an angle is done as follows
x += cos(angle)*speed
y += sin(angle)*speed
You may need to convert the angle to radians first (radians = angle * pi / 180).

If you want a lot of bullets I suggest creating a lookup table (I assume Blitmax just does the raw calculations), because trigonometry functions can be a bit slow.
Title: Re: Programming Q&A
Post by: Xiphirx on August 28, 2008, 03:22:20 am
Moving at an angle is done as follows
x += cos(angle)*speed
y += sin(angle)*speed
You may need to convert the angle to radians first (radians = angle * pi / 180).

If you want a lot of bullets I suggest creating a lookup table (I assume Blitmax just does the raw calculations), because trigonometry functions can be a bit slow.

That worked, thanks.
Title: Re: Programming Q&A
Post by: Xiphirx on August 31, 2008, 02:01:36 am
Another BlitzMax question:

How do I set the rotation point to something other than the top-left corner?

I want to center the point.
Title: Re: Programming Q&A
Post by: Infinitus on August 31, 2008, 07:39:16 pm
setimagehandle(image, x, y)
Title: Re: Programming Q&A
Post by: Xiphirx on August 31, 2008, 07:40:52 pm
setimagehandle(image, x, y)

<3
Title: Re: Programming Q&A
Post by: MG-Zero on September 05, 2008, 12:15:43 am
Why the !@#$% don't you work?  Stupid Java >_>

letters.java
Code: [Select]
import java.io.*;

public class letters
{

        public static void main(String[] args)
        {

               System.out.println ("hello world!");
        }
}

I'm just doing a simple hello world app.  It compiles no problems through javac.exe but when I run letters.class through java.exe....I get this in my console window:

(http://img.photobucket.com/albums/v83/mastergohan/watsajaver.png)

edit: nevermind, it was a directory issue.
Title: Re: Programming Q&A
Post by: Wasabi on September 06, 2008, 07:36:13 am
just a quick question, what would the best .net framework be to work with and target a c# application?
Title: Re: Programming Q&A
Post by: AcidGame on September 06, 2008, 02:21:39 pm
Darklight: My personal preference for C# is .NET 2.0. It contains all the nice and well-needed updates (generic classes, etc...) and is the last version to be supported on the old Windows operating systems (Windows 2000/ME/98).

The newer versions appear to be mainly targeted at Vista (with most of the additional features being for Vista compatibility). There doesn't appear to be any major functionality that you would lose by using .NET 2.0, and you can potentially support the older versions of Windows if you have to.

It all depends on what you need.
Title: Re: Programming Q&A
Post by: Wasabi on September 07, 2008, 01:54:51 am
Darklight: My personal preference for C# is .NET 2.0. It contains all the nice and well-needed updates (generic classes, etc...) and is the last version to be supported on the old Windows operating systems (Windows 2000/ME/98).

The newer versions appear to be mainly targeted at Vista (with most of the additional features being for Vista compatibility). There doesn't appear to be any major functionality that you would lose by using .NET 2.0, and you can potentially support the older versions of Windows if you have to.

It all depends on what you need.
yeah, I should have really said I wanted to support at least XP/vista.
Thanks, I just wasn't sure how much functionality I'd loose by using an older version of .NET.
Title: Re: Programming Q&A
Post by: Xiphirx on September 08, 2008, 01:08:57 am
Code: [Select]
SuperStrict
'//Set Up ----------------------------------------------------//
'--------//Create a list of all active objects
Global ObjList:TList=CreateList()
'--------//Set the Graphical window up
Global ScreenWidth:Int = 420
Global ScreenHeight:Int = 272
Graphics ScreenWidth, ScreenHeight, 0
SetGraphicsDriver GLMax2DDriver()

'//Intro Credit screen ---------------------------------------//
Local i:Float = 0
Local titleimage:TImage = LoadImage("GFX\startup.png", FILTEREDIMAGE)
SetBlend ALPHABLEND
For i = 0 To 1 Step .1
SetAlpha i
If KeyDown(KEY_ESCAPE) Or AppTerminate() End
DrawImage(titleimage, 0, 0)
Next

SetAlpha 1
Cls
SetBlend SOLIDBLEND

"Unhandeled Exception: Attempt to access field or method of null object"

???
Title: Re: Programming Q&A
Post by: Infinitus on September 08, 2008, 01:16:27 am
Wow, that has so many errors in it I don't know where to start. The thing probably causing your error though is that it can't find GFX\startup.png
Title: Re: Programming Q&A
Post by: Xiphirx on September 08, 2008, 01:22:02 am
Wow, that has so many errors in it I don't know where to start. The thing probably causing your error though is that it can't find GFX\startup.png

No the LoadImage is correct, startup.png is located in GFX.

BTW, Infini, this is my 2nd time using it, not as my second time attempting, this is actually my second time opening MaxIDE.

It has a bunch of errors, probably all of those useless global declarations, but I will fix that later.
Title: Re: Programming Q&A
Post by: Infinitus on September 08, 2008, 01:23:17 am
It may be there but is it being loaded. Stick a debugstop directly after the loadimage call and check that titleImage is actually valid.
Title: Re: Programming Q&A
Post by: Xiphirx on September 08, 2008, 01:35:49 am
Fixed, it was that driver declaration -_-.
Title: Re: Programming Q&A
Post by: Xiphirx on September 22, 2008, 08:47:49 pm
Is there any way to stretch an image to a certain width in BlitzMax? the forums and Google don't seem to know.
Title: Re: Programming Q&A
Post by: Infinitus on September 22, 2008, 08:50:03 pm
SetScale?
Title: Re: Programming Q&A
Post by: Xiphirx on September 22, 2008, 08:52:29 pm
SetScale?

That didn't work. Probably should have said that I tried SetScale. SetScale uses a percentage and I want pixel width not percentage width.

EDIT: I fixed it by making a formula to convert the percentages to pixels >__>
Title: Re: Programming Q&A
Post by: Infinitus on September 22, 2008, 09:14:24 pm
u_u. I think thats obvious. You just use something like this;

setscale(float(new_width) / float(image_width), float(new_height) / float(image_height))
Title: Re: Programming Q&A
Post by: MG-Zero on September 29, 2008, 04:07:45 pm
Got some array and pointer dickery going on here..

Code: [Select]
template <typename T> void HVSTDAT<T>::addData(T data)
{
tempData = new T[dataCount]; //set up the temp holder

for (int i = 0; i < dataCount; i++)
{
tempData[i] = mainData[i];
}

dataCount++;

delete mainData; //clear out the main data
mainData = new T[dataCount]; //recreate it with an extra space

for (int i = 0; i < dataCount - 1; i++)
{
mainData[i] = tempData[i];
}

mainData[dataCount] = data; //put in the new data
delete tempData; //get rid of the temp data
}



template <typename T> void HVSTDAT<T>::listData()
{
for (int i = 0; i < dataCount; i++)
{
std::cout << i + 1 << ": " << mainData[i] <<"\n";
}
}


int main()
{

int x = 4;
int p = 2;
HVSTDAT<int> test(x);
test.addData(p);
test.listData();
system("pause");
return 0;
}

2 functions there using a pointer and an array to hold some data and output it.  Going by the main function, the output should be:

Quote
1: 4
2: 6

well, here's the output...

Quote
1: 4
2: -842150451

umm... -842150451 != 6   I've gone through the functions too many times, I can't figure out what's wrong.

wat.

EDIT: Had a variable error, fixed.
Title: Re: Programming Q&A
Post by: Xiphirx on October 12, 2008, 12:05:24 am
Code: [Select]
function GetContent(url, method, place, params)
{
switch (method){
case "GET":
var kl = window.location.href.indexOf("?",0);
lastpage = window.location.href.substr(kl);
document.getElementById(place).innerHTML = "<center>Loading, please wait...<br /><img src='load.gif' /></center>";
thing = new DICKBUTT();
thing.open("GET", url, true);
glb_location = place;
thing.onreadystatechange = updatePage;
thing.send(null);
lastpage = GetDo();
break;
case "POST":
document.getElementById(place).innerHTML = "<center>Your request is being processed, please wait...<br /><img src='load.gif' /></center>";
thing = new DICKBUTT();
thing.onreadystatechange = updatePage;
thing.open("POST", url, true);
thing.setRequestHeader("Content-type", "applicationx-www-form-urlencoded");
thing.setRequestHeader("Content-length", params.length);
thing.setRequestHeader("Connection", "close");
glb_location = place;
thing.send(params);
break;
}
}

function SubmitShout(form)
{
alert("1");
var message = form.message.value;
var name = form.name.value;
var check = 0;
alert("2");
if (name.length < 3)
{
form.name.className = 'error';
check = 1;
return false;
}
alert("3");
if (message.length < 3)
{
form.message.className = 'error';
check = 1;
return false;
}
alert("4");
alert("5");
if (check === 0) {
var zeparams = "message="+message+"&name="+name;
GetContent("shoutbox.php", "POST", "shoutform", zeparams);
return false;
}
return false;
}

The POST request does not work... Anything look wrong? I have gone through it many times :S

Also, you may see a ton of alerts, well that is for debugging, and it goes to 5
Title: Re: Programming Q&A
Post by: MG-Zero on October 19, 2008, 06:21:12 pm
Is there a way to convert a char value into into an int, double, or float in C++?  I don't mean grabbing it's ascii value, I mean turning it into an actual number.  I.E. if the char value was "1.5", is there a way to put that value into a double?  I basically need a cdbl() function like in Basic..
Title: Re: Programming Q&A
Post by: Infinitus on October 19, 2008, 06:25:24 pm
Is there a way to convert a char value into into an int, double, or float in C++?  I don't mean grabbing it's ascii value, I mean turning it into an actual number.  I.E. if the char value was "1.5", is there a way to put that value into a double?  I basically need a cdbl() function like in Basic..
Come again? Do you mean converting a character string into a value? If so, read up on atoi, atof and atol.
Title: Re: Programming Q&A
Post by: MG-Zero on October 19, 2008, 06:57:27 pm
yes, exactly.  I'll look into those, thanks.

But now I've got another problem.  I'm working with some streams, but the damn files keep truncating when I open them.

Code: [Select]
IOData.inFile.open(fileName);
inFile is an ifstream instance.  How do I stop them from truncating?
Title: Re: Programming Q&A
Post by: Infinitus on October 19, 2008, 07:02:23 pm
If reading;
Code: [Select]
IOData.inFile.open(fileName, ios_base::openmode::in);

If appending;
Code: [Select]
IOData.inFile.open(fileName, ios_base::openmode::out | ios_base::openmode::app);

Not checked mind you. Should work though.
Title: Re: Programming Q&A
Post by: MG-Zero on October 19, 2008, 07:08:45 pm
Nope, didn't work  :(
Title: Re: Programming Q&A
Post by: Infinitus on October 19, 2008, 07:42:22 pm
Nope, didn't work  :(
Looks like your doing something wrong then. Post full code please.
Title: Re: Programming Q&A
Post by: MG-Zero on October 20, 2008, 01:06:47 am
It's fixed.  Someone over at gamedev pointed out my error...I used = in an if statement instead of == -.-  Well, don't I feel dumb now.
Title: Re: Programming Q&A
Post by: Cassyblanca on October 20, 2008, 01:08:31 am
It's fixed.  Someone over at gamedev pointed out my error...I used = in an if statement instead of == -.-  Well, don't I feel dumb now.
Don't feel bad, I'd had the same problem with a window closing a couple years ago when I was first messing around with Win32 programming & DX7 :D

When I was checking the message, I did an "= WM_QUIT" instead of "== WM_QUIT"

It happens <3
Title: Re: Programming Q&A
Post by: Bludleef on October 20, 2008, 01:13:13 am
It's fixed.  Someone over at gamedev pointed out my error...I used = in an if statement instead of == -.-  Well, don't I feel dumb now.
Don't feel bad, I'd had the same problem with a window closing a couple years ago when I was first messing around with Win32 programming & DX7 :D

When I was checking the message, I did an "= WM_QUIT" instead of "== WM_QUIT"

It happens <3
Exactly 9/10 times any error in code has to do with simple syntax.
Title: Re: Programming Q&A
Post by: Xiphirx on November 02, 2008, 02:38:54 am
Code: [Select]
var lastpage = "notset";
var glb_location;
var thing;
var poststr;

function DICKBUTT()
{
var request;

try {request = new XMLHttpRequest();}
catch (err)
{
try {request = new ActiveXObject("Msxml2.XMLHTTP");}
catch (err)
{
try{request = new ActiveXObject("Microsoft.XMLHTTP");}
catch (err)
{
alert("Your Browser does not support DICKBUTT, which is needed to view this website. Please upgrade to the latest version of your favorite browser.");
return false;
}
}
}
alert(request);
return request;

}

function GetContent(url, method, place, params)
{
switch (method){
case "GET":
alert("1");
var kl = window.location.href.indexOf("?",0);
alert("2");
lastpage = window.location.href.substr(kl);
alert("3");
document.getElementById(place).innerHTML = "<center>Loading, please wait...<br /><img src='img/load.gif' /></center>";
alert("4");
thing = new DICKBUTT();
alert("5");
thing.open("GET", url, true);
alert("6");
glb_location = place;
alert("7");
thing.onreadystatechange = updatePage;
alert("8");
thing.send(null);
lastpage = GetDo();
break;
case "POST":
document.getElementById(place).innerHTML = "<center>Your request is being processed, please wait...<br /><img src='img/load.gif' /></center>";
thingp = new DICKBUTT();
thingp.open("POST", url, true);
thingp.setRequestHeader("Content-type", "applicationx-www-form-urlencoded; charset=UTF-8");
thingp.setRequestHeader("Content-length", params.length);
thingp.setRequestHeader("Connection", "close");
glb_location = place;
thingp.send(params);
thingp.onreadystatechange = updatePage;
break;
}
}

function updatePage()
{
var location = glb_location;
if (thing.readyState == 4)
{
if (thing.status !== 200)
{
document.getElementById(location).innerHTML = "Error, "+thing.status+"";
}
else
{
document.getElementById(location).innerHTML = thing.responseText;
}
}
}

function GetDo()
{
var loc = window.location.href;
var idx = loc.indexOf("?", 0);
var stn = loc.substr(idx);
return stn;
}

function CheckDo()
{
if (GetDo().length > 1 && GetDo() != lastpage)
{
lastpage = GetDo();
GetContent("maincontent.php"+GetDo(), "GET", "here","");
return true;
}
return false;
}

function INI()
{
if (CheckDo() == false)
{
GetContent("maincontent.php?do=home", "GET", "here","");
alert("sdf");
return true;
}
return false;
}

What it does: Basically, I put <body onLoad="INI();"> to make sure that when someone visits my site they get content loaded.

Now it works perfectly in FF <3
Now IE doesnt load anything, it has my outputted text "Loading..." and never loads anything.

But I have gotten the DICKBUTT to work in IE, so for example I load my site and click on a menu link, it loads perfectly in both browsers.

For those alerts,

When you first get to my site the alerts go up to 5, so
      thing.open("GET", url, true);
is wrong for some reason.
The alert in the DICKBUTT() function returns "[object]" which is true for all of the pages that have working DICKBUTT, so that is not the problem.

Why can't IE load at the initial view? Is there something wrong with my code?
Title: Re: Programming Q&A
Post by: Xiphirx on November 23, 2008, 11:43:02 pm
I am currently trying to put a simple authentication system in the mean time for my shoutbox.

I decided that I want to use tripcode because it was easy.

I have one question:

How do I convert UTF 8 to Shift JIS? in Javascript? is it possible? I haven't gotten any results from google... and the code that I have seen is done in Ruby.
Title: Re: Programming Q&A
Post by: Infinitus on November 23, 2008, 11:45:20 pm
lol, why in hells name do you want japanease character encoding.

Anyhow I'm not sure, haven't got enough information about it. Post the ruby code, might be helpfull.
Title: Re: Programming Q&A
Post by: Xiphirx on November 23, 2008, 11:48:31 pm
Quote
The tripcode function works as follows:

   1. Convert the input to Shift JIS.
   2. Replace the characters &, <, >, ", and ' with &amp;, &lt;, &gt;, &quot;, and ' respectively. Some implementations replace other characters as well, these are the most common ones.
   3. Generate the salt as follows:
         1. Take the second and third characters of the input with H.. appended to it.
         2. Replace any characters not between . and z with ..
         3. Replace any of the characters in :;<=>?@[\\]^_` with the corresponding character from ABCDEFGabcdef.
   4. Call the crypt() function with the input and salt.
   5. Return the last 10 characters.

Some buggy implementations don't convert to Shift JIS. The original implementation of tripcodes only used the last 8 characters.

Well, since I don't really know anything about Tripcode other than the fact that it differentiates users on messages boards etc. I decided to follow Wikipedia

Anyway here is the ruby (sorry, it was python :P) code:
Code: [Select]
import re, string, crypt

def mktripcode(pw):
    pw = pw.decode('utf_8', 'ignore') \
        .encode('shift_jis', 'ignore')    \
        .replace('"', '&quot;')      \
        .replace("'", ''')           \
        .replace('<', '&lt;')        \
        .replace('>', '&gt;')        \
        .replace(',', ',')
    salt = (pw + '...')[1:3]
    salt = re.compile('[^\.-z]').sub('.', salt)
    salt = salt.translate(string.maketrans(':;<=>?@[\\]^_`', 'ABCDEFGabcdef'))
    trip = crypt.crypt(pw, salt)[-10:]
    return trip

print mktripcode(PASSWORD)

It doesn't really help since it has a function to do it...
Title: Re: Programming Q&A
Post by: Infinitus on November 23, 2008, 11:51:23 pm
*scratchs head*

Seriously, why? The conversion to japanease just seems so incredibly pointless. Not to mention you can generate a tripcode equivilent in so many easier ways.
Title: Re: Programming Q&A
Post by: Xiphirx on November 23, 2008, 11:53:20 pm
*scratchs head*

Seriously, why? The conversion to japanease just seems so incredibly pointless. Not to mention you can generate a tripcode equivilent in so many easier ways.

I was just following the Wikipedia algorithm because I don't know better :P

Anyway, what else can I do? Convert it to another encoding type?
Title: Re: Programming Q&A
Post by: Infinitus on November 23, 2008, 11:55:41 pm
*scratchs head*

Seriously, why? The conversion to japanease just seems so incredibly pointless. Not to mention you can generate a tripcode equivilent in so many easier ways.

I was just following the Wikipedia algorithm because I don't know better :P

Anyway, what else can I do? Convert it to another encoding type?

The only reason I can think that you would wish to follow wikis algorithem is so that tripcodes are consistent across all other sites that use the same algorithem. But to be fair, when is that going to directly matter to you? Why not just hash the users password concatinated with a salt, and extract the first 8 or so characters from the result.
Title: Re: Programming Q&A
Post by: Xiphirx on November 23, 2008, 11:56:56 pm
*scratchs head*

Seriously, why? The conversion to japanease just seems so incredibly pointless. Not to mention you can generate a tripcode equivilent in so many easier ways.

I was just following the Wikipedia algorithm because I don't know better :P

Anyway, what else can I do? Convert it to another encoding type?

The only reason I can think that you would wish to follow wikis algorithem is so that tripcodes are consistent across all other sites that use the same algorithem. But to be fair, when is that going to directly matter to you? Why not just hash the users password concatinated with a salt, and extract the first 8 or so characters from the result.

Easy. Thanks, I just thought it "had" to be that way.

:)
Title: Re: Programming Q&A
Post by: Infinitus on November 23, 2008, 11:58:03 pm
Quote
$secretSalt = "InsertSuperSecretSaltHerePlz";

function CreateTripCode_Plz_KThxBai($password)
{
   global $secretSalt;
   return substr(md5($password . $secretSalt), 0, 8 );
}


etc, etc.
Title: Re: Programming Q&A
Post by: Xiphirx on November 24, 2008, 12:07:08 am
K I will CreateTripCode_Plz_KThxBai.
Title: Re: Programming Q&A
Post by: Xiphirx on November 25, 2008, 06:29:22 am
Quick question:

Say I have 1 .Net program running. This application has 1 input box and 1 output box.

Is there ANY possible way I can get the text in the output box and put text in the input box using a program I made?

Preferably VB...
Title: Re: Programming Q&A
Post by: Infinitus on November 25, 2008, 01:29:18 pm
inputBox.Text = outputBox.Text;

???
Title: Re: Programming Q&A
Post by: MG-Zero on November 25, 2008, 03:14:13 pm
inputBox.Text = outputBox.Text;

???


This but without the semi colon.
Title: Re: Programming Q&A
Post by: Cassyblanca on November 25, 2008, 08:02:55 pm
I believe he's referring to doing it from an external application.
Title: Re: Programming Q&A
Post by: Infinitus on November 25, 2008, 09:51:50 pm
In that case. Quite easily using the winapi functions. However it depends on how the program is configured. Some (such as MSN) use windowless controls which makes it impossible (well not impossible, but dam hard) for outside applications to directly modify the controls.
Title: Re: Programming Q&A
Post by: Xiphirx on November 26, 2008, 04:23:25 am
Woops, I just read my post and let me clarify...

1 program running, has input box and output box.

I want to make another program that will read the output of Program 1 and input something into Program 1's input box.

Preferably VB.

Now with winapi, would it make it harder if I tried to do it with a VB application inputting into a .NET application?

I don't think the program has some super !@#$% protection, its a simple server application so that shouldn't be a problem. :)
Title: Re: Programming Q&A
Post by: Infinitus on November 26, 2008, 07:09:24 am
Quote
Now with winapi, would it make it harder if I tried to do it with a VB application inputting into a .NET application?
Nope. .NET or VB, still uses the same windows framework.

I'll write an example when I get back from college.
Title: Re: Programming Q&A
Post by: Xiphirx on November 26, 2008, 07:10:52 am
Quote
Now with winapi, would it make it harder if I tried to do it with a VB application inputting into a .NET application?
Nope. .NET or VB, still uses the same windows framework.

I'll write an example when I get back from college.

Thank you :3.

EDIT:

http://www.xtremevbtalk.com/showthread.php?t=148226

Quote
Hi budgieboy, welcome to the forum!

I'm not an expert, but have done something similar recently and will try to pass on what I learnt about sending keystrokes to other applications. There are several ways to send keystrokes from a VB program :

1) Use the built-in VB 'SendKeys' statement. You call this and pass a string which is input to the current active window. This is the easiest to code but you have to find and active your chosen window before you can call SendKeys. Also, many people (including me!) have had problems with SendKeys and it doesn't seem to work in some situations.

2) Use the SendInput API. This can be used to simulate both Mouse and Keyboard input to the current active window. This is more difficult to code and requires other API's to move and copy memory around before you call SendInput. This method seems to work for most people, but I had some problems with it (nothing wrong with the API or my code, but the type of application I was sending input to ).

3) Use the SendMessage or PostMessage API. Any Windows message (e.g. keyboard, mouse, paint etc.) can be sent to ANY application using these API calls, whether the application has the focus or not. This is very flexible and the window doesn't need to have the focus for this to work. If you use SendMessage then your VB program should wait for the target application to process the messages before continuing. With PostMessage, your VB program will post the messages and then continue immediately.


In summary, for my needs I ended up using PostMessage which worked great. I suggest trying the above options in order (i.e. easiest first) to see which works for you. Haven't got time to post code examples, but do a search on this forum or on google for any of the above and you'll have no problem finding code.

To answer your question about finding the previously active application, I don't think you need to if you use SendMessage/PostMessage and these will send to any Window you like, whether it has the focus or not. If you really need to then I believe there must be some API's to do with the zOrder of Applications (i.e. the order they appear when you press ALT+TAB). Anyone got any ideas?

Oh, one more thing... if you need to find and activate a window, try the following API's :

FindWindow
SetForegroundWindow

Hope this helps .

I believe this is what I am looking for?
Title: Re: Programming Q&A
Post by: Xiphirx on November 27, 2008, 11:36:51 pm
Sorry for the double post (lol I need to leave this topic >_>;).

So, PostMessage, I think that is what I am looking for and I tried to do something with notepad...

MODULE CODE
Code: [Select]
Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String _
) As Long

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    ByVal hWndParent As Long, _
    ByVal hWndChildAfter As Long, _
    ByVal lpszClassName As String, _
    ByVal lpszWindowName As String _
) As Long

Declare Function PostMessage Lib "user32" _
   Alias "PostMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Long) As Long
Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long



FORM CODE
Code: [Select]


Private Sub Form_Load()
' Find Notepad's handle
Dim hWndNotepad As Long

hWndNotepad = FindWindow("Notepad", vbNullString)

' Find the handle of the textbox, within the Notepad window
Dim hWndTextbox As Long
hWndTextbox = FindWindowEx(hWndNotepad, 0&, "Edit", vbNullString)
Call PostMessage(hWndTextbox, 3535, 0&, 0&)

Dim retval As Long

retval = SetForegroundWindow(hWndNotepad)

End Sub

Now What I am trying to accomplish here is setting whatever is in Notepad to "3535"...

I am getting the correct handle of the notepad window. I am just messing around, I am wondering if I am using PostMessage correctly?

Also, am I supposed to use PostMessage?
Title: Re: Programming Q&A
Post by: Infinitus on November 28, 2008, 12:07:47 am
I'm really not sure why your setting the text in this obtuse way, why not just open notepad with the command line of a text document to open?

Anyhow, heres some C# code to do it. Shouldn't be hard to convert.

Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NotepadSet
{
    public class Program
    {
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);

        public const int WM_SETTEXT = 0xC;

        public static void Main(string[] args)
        {
            IntPtr hWnd = FindWindow("Notepad", null);
            if (hWnd != IntPtr.Zero)
            {
                IntPtr hWndTextbox = FindWindowEx(hWnd, IntPtr.Zero, "Edit", null);
                if (hWndTextbox != IntPtr.Zero)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder("My awesome text goes here.");
                    SendMessage(hWndTextbox, WM_SETTEXT, IntPtr.Zero, sb);
                }
            }
        }
    }
}
Title: Re: Programming Q&A
Post by: Xiphirx on November 28, 2008, 12:20:44 am
I'm really not sure why your setting the text in this obtuse way, why not just open notepad with the command line of a text document to open?

Anyhow, heres some C# code to do it. Shouldn't be hard to convert.

Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace NotepadSet
{
    public class Program
    {
        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true)]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);

        [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
        public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, StringBuilder lParam);

        public const int WM_SETTEXT = 0xC;

        public static void Main(string[] args)
        {
            IntPtr hWnd = FindWindow("Notepad", null);
            if (hWnd != IntPtr.Zero)
            {
                IntPtr hWndTextbox = FindWindowEx(hWnd, IntPtr.Zero, "Edit", null);
                if (hWndTextbox != IntPtr.Zero)
                {
                    System.Text.StringBuilder sb = new System.Text.StringBuilder("My awesome text goes here.");
                    SendMessage(hWndTextbox, WM_SETTEXT, IntPtr.Zero, sb);
                }
            }
        }
    }
}

Quote
System.Text.StringBuilder sb = new System.Text.StringBuilder("My awesome text goes here.");

That line is my only problem....

EDIT:

Setting the text of Notepad is just a beginner thing till I set the text in a Server tool...
Title: Re: Programming Q&A
Post by: Infinitus on November 28, 2008, 12:23:23 am
Just pass a string to the SendMessage function rather than a StringBuilder class. StringBuilder and similar classes are just C#'s way of abstracting the interop data casting.

EDIT: Word of warning, of your server tool has any passwords boxs you wish to set or get; It won't work. Windows protects them, they can only be accessed by their creator processes.
Title: Re: Programming Q&A
Post by: Xiphirx on November 28, 2008, 09:20:08 pm
Just pass a string to the SendMessage function rather than a StringBuilder class. StringBuilder and similar classes are just C#'s way of abstracting the interop data casting.

EDIT: Word of warning, of your server tool has any passwords boxs you wish to set or get; It won't work. Windows protects them, they can only be accessed by their creator processes.

ok

I just tried this, and no error come up, but nothing appears in notepad...

Code: [Select]
' Find Notepad's handle
Dim hWndNotepad As Long
Dim sb As String

sb = "lol"


hWndNotepad = FindWindow("Notepad", vbNullString)


' Find the handle of the textbox, within the Notepad window
Dim hWndTextbox As Long
hWndTextbox = FindWindowEx(hWndNotepad, 0&, "Edit", vbNullString)
Call SendMessage(hWndTextbox, 0, 0, sb)

Code: [Select]
Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    ByVal hWnd As Long, ByVal Msg As Long, _
    wParam As Any, lParam As Any) As Long
   
Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
    ByVal lpClassName As String, _
    ByVal lpWindowName As String _
) As Long

Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
    ByVal hWndParent As Long, _
    ByVal hWndChildAfter As Long, _
    ByVal lpszClassName As String, _
    ByVal lpszWindowName As String _
) As Long

Title: Re: Programming Q&A
Post by: Infinitus on November 28, 2008, 09:55:17 pm
Second parameter of SendMessage needs to be WM_SETTEXT
Title: Re: Programming Q&A
Post by: Xiphirx on November 28, 2008, 10:19:25 pm
Second parameter of SendMessage needs to be WM_SETTEXT

Ok, now WM_SETTEXT needs to equal 0xC correct? How do I define that then? what data type ... When I define it like an integer (in your c# example) VB throws an error specifically because of the "x" in 0xC
Title: Re: Programming Q&A
Post by: Infinitus on November 28, 2008, 10:21:56 pm
0x is the prefix used in C languages for declaring a numeric literal as hexidecimal. I believe in VB you use &H instead.
Title: Re: Programming Q&A
Post by: Xiphirx on November 28, 2008, 10:27:46 pm
OK!, I finally got it work, but there is a simple problem (at least I hope so)

sb = "lol"

In notepad, it outputted "¬»"
Title: Re: Programming Q&A
Post by: Infinitus on November 28, 2008, 10:38:43 pm
Sounds like its not getting the data correctly. Probably have to pass a pointer, or a block of memory rather than a string (not sure how VB deals with casting between native and inbuilt data types).
Title: Re: Programming Q&A
Post by: Xiphirx on November 28, 2008, 10:43:22 pm
Sounds like its not getting the data correctly. Probably have to pass a pointer, or a block of memory rather than a string (not sure how VB deals with casting between native and inbuild data types).

I'll go check on a VB forum. Thanks Infini!
Title: Re: Programming Q&A
Post by: Xiphirx on November 29, 2008, 02:28:36 am
I have found the solution, another problem that I tried to tackle. I think I am doing it right

Basically:
CSPSPServer
-Form1 [CSPSPServer.Form1]
----label1 [System.Windows.Forms.Label]
----inputBox [System.Windows.Forms.TextBox]
----outputBox [System.Windows.Forms.RichTextBox]

Now, I know that the names in the brackets are the class names, but I am still unable to get the handle of the inputBox successfully...

Code: [Select]
' Find Server handle
Dim hWndServer As Long
Dim hWndForm As Long
Dim sb As String
Dim WM_SETTEXT As Integer

WM_SETTEXT = &HC

sb = "Test"


hWndServer = FindWindow(vbNullString, "CSPSPServer") //Find the program

hWndForm = FindWindowEx(hWndServer, 0, "CSPSPServer.Form1", vbNullString) //Find the form


' Find the handle of the textbox, within the Server window
Dim hWndTextbox As Long
hWndTextbox = FindWindowEx(hWndServer, 0&, vbNullString, "inputBox") //Find inputBox

Call SendMessage(hWndTextbox, WM_SETTEXT, 0, sb)
Call SetForegroundWindow(hWndServer)

MsgBox (hWndForm) //outputs 0
MsgBox (hWndTextbox) //outputs 0

Am I doing this the right way?
Title: Re: Programming Q&A
Post by: MG-Zero on December 01, 2008, 02:14:34 am
How can I use the GetAsyncKeyState() function in C++ to check if no key is pressed?  I've tried passing NULL to the parameter, but it didn't work.
Title: Re: Programming Q&A
Post by: Xiphirx on December 01, 2008, 03:15:56 am
How can I use the GetAsyncKeyState() function in C++ to check if no key is pressed?  I've tried passing NULL to the parameter, but it didn't work.
Try VK_NONAME

EDIT

Alternatively you can just put a if ! statement with all of the Keys used in your program. This is a very bad solution though...

My question:

If I have a multiline message, how do I only read the last line?

Maybe do a search for a "new line" character?...
Title: Re: Programming Q&A
Post by: Infinitus on December 01, 2008, 01:09:02 pm
I have found the solution, another problem that I tried to tackle. I think I am doing it right

Basically:
CSPSPServer
-Form1 [CSPSPServer.Form1]
----label1 [System.Windows.Forms.Label]
----inputBox [System.Windows.Forms.TextBox]
----outputBox [System.Windows.Forms.RichTextBox]

Now, I know that the names in the brackets are the class names, but I am still unable to get the handle of the inputBox successfully...

Code: [Select]
' Find Server handle
Dim hWndServer As Long
Dim hWndForm As Long
Dim sb As String
Dim WM_SETTEXT As Integer

WM_SETTEXT = &HC

sb = "Test"


hWndServer = FindWindow(vbNullString, "CSPSPServer") //Find the program

hWndForm = FindWindowEx(hWndServer, 0, "CSPSPServer.Form1", vbNullString) //Find the form


' Find the handle of the textbox, within the Server window
Dim hWndTextbox As Long
hWndTextbox = FindWindowEx(hWndServer, 0&, vbNullString, "inputBox") //Find inputBox

Call SendMessage(hWndTextbox, WM_SETTEXT, 0, sb)
Call SetForegroundWindow(hWndServer)

MsgBox (hWndForm) //outputs 0
MsgBox (hWndTextbox) //outputs 0

Am I doing this the right way?

The class names and window names are NOT the same thing that you would see in a .NET designer, don't assume they are. Use Spy++ or something similar to find out what they are.

Quote
If I have a multiline message, how do I only read the last line?

Maybe do a search for a "new line" character?...
I believe the .NET string class has a method called .split which you can use to split a message up into lines, just take the last in the splitted array.
Title: Re: Programming Q&A
Post by: MG-Zero on December 01, 2008, 01:39:07 pm
How can I use the GetAsyncKeyState() function in C++ to check if no key is pressed?  I've tried passing NULL to the parameter, but it didn't work.
Try VK_NONAME

didn't work >_>
Title: Re: Programming Q&A
Post by: Moon_child on December 17, 2008, 09:53:09 am
Is there a good free library on teh interwebz that lets you play mp3 files in your C, C++ project?
Title: Re: Programming Q&A
Post by: Windy on December 17, 2008, 12:07:27 pm
fmod, as long as you have no intention to sell.
Title: Re: Programming Q&A
Post by: Cassyblanca on December 17, 2008, 04:22:20 pm
http://audiere.sourceforge.net/

Audiere is a GPL'd audio engine. It's also wonderful as hell.
Title: Re: Programming Q&A
Post by: Xiphirx on December 20, 2008, 12:54:32 am
I currently have a Do loop as so:

Code: [Select]
Do
            DoEvents
            'Check the log for messages...
            lSize = SendMessage(hWndOutbox, WM_GETTEXTLENGTH, 0&, ByVal 0&)
            If lSize > 0 Then
                sBuf = String(lSize + 2, " ")
                lRet = SendMessage(hWndOutbox, WM_GETTEXT, ByVal lSize + 1, ByVal sBuf)
                If lRet > 0 Then
                   LogText = Left$(sBuf, lSize + 2)
                   'Do things with the server text...
                   
                   'Goodbye message#######################################################
                    If chkGoodbye.Value = 1 Then
                        If (InStr(1, LogText, "disconnected", vbTextCompare) > 0) And (InStr(LogText, ":") < 1) And (InStr(LogText, "(#") > 0) Then
                            'Send a goodbye message
                            For G = 1 To Len(LogText) Step 1
                                TheChar = Mid$(LogText, G, 2)
                                If TheChar = "(#" Then
                                    Exit For
                                End If
                            Next
                            Call SendMessage(hWndTextbox, WM_SETTEXT, 0, txtGoodbye.Text & Mid$(LogText, 1, G - 1))
                            Call PostMessage(hWndTextbox, WM_KEYDOWN, VK_RETURN, 0)
                            Sleep (200)
                            txtPlayers.Text = Replace(txtPlayers.Text, Mid$(LogText, 1, G - 1), "")
                        End If
                    End If
                   'Welcome message#######################################################
                    If chkWelcome.Value = 1 Then
                        If (InStr(1, LogText, "connected", vbTextCompare) > 0) And (InStr(1, LogText, "disconnected", vbTextCompare) < 1) And (InStr(1, LogText, ":", vbTextCompare) < 1) And (InStr(LogText, "(#") > 0) Then
                            'Send a welcome message
                            For G = 1 To Len(LogText) Step 1
                                TheChar = Mid$(LogText, G, 2)
                                If TheChar = "(#" Then
                                    Exit For
                                End If
                            Next
                            Call SendMessage(hWndTextbox, WM_SETTEXT, 0, txtWelcomeMsg.Text & Mid$(LogText, 1, G - 1))
                            Call PostMessage(hWndTextbox, WM_KEYDOWN, VK_RETURN, 0)
                            Sleep (200)
                            txtPlayers.Text = txtPlayers.Text & vbNewLine & Mid$(LogText, 1, G - 1)
                        End If
                    End If
                    'Ban ##########################################################
                    If chkInvokeBan.Value = 1 Then
                        If (InStr(1, LogText, "connected", vbTextCompare) > 0) And (InStr(1, LogText, "disconnected", vbTextCompare) < 1) And (InStr(1, LogText, ":", vbTextCompare) < 1) And (InStr(LogText, "(#") > 0) Then
                            For G = 1 To Len(LogText) Step 1
                                    TheChar = Mid$(LogText, G, 2)
                                    If TheChar = "(#" Then
                                        Exit For
                                    End If
                            Next
                            P = G
                            If (InStr(1, txtBanList.Text, Mid$(LogText, 1, G - 1), vbTextCompare) > 0) Then
                                For G = 1 To Len(LogText) Step 1
                                    TheChar = Mid$(LogText, G, 11)
                                    If TheChar = ") connected" Then
                                        Exit For
                                    End If
                                Next
                                Call SendMessage(hWndTextbox, WM_SETTEXT, 0, "/kick " & Mid$(LogText, P + 2, G - 1))
                                Call PostMessage(hWndTextbox, WM_KEYDOWN, VK_RETURN, 0)
                                Sleep (200)
                            End If
                        End If
                    End If
                   'Time ping ####################################################### <=== NOT WORKING@!!@@!
                    If chkTime.Value = 1 Then
                        If (InStr(1, LogText, "thetime", vbTextCompare) > 0) And (InStr(1, LogText, ":", vbTextCompare) > 0) Then
                            Call SendMessage(hWndTextbox, WM_SETTEXT, 0, "/timeleft")
                            Call PostMessage(hWndTextbox, WM_KEYDOWN, VK_RETURN, 0)
                            Sleep (200)
                            lSize = SendMessage(hWndOutbox, WM_GETTEXTLENGTH, 0&, ByVal 0&)
                            If lSize > 0 Then
                                sBuf = String(lSize + 2, " ")
                                lRet = SendMessage(hWndOutbox, WM_GETTEXT, ByVal lSize + 1, ByVal sBuf)
                                If lRet > 0 Then
                                    LogText = Left$(sBuf, lSize + 2)
                                End If
                            End If
                            lSize2 = SendMessage(hWndOutbox, WM_GETTEXTLENGTH, 0&, ByVal 0&)
                            If lSize2 > 0 Then
                                sBuf2 = String(lSize + 2, " ")
                                lRet2 = SendMessage(hWndOutbox, WM_GETTEXT, ByVal lSize2 + 1, ByVal sBuf2)
                                If lRet2 > 0 Then
                                    LogText2 = Left$(sBuf2, lSize2 + 2)
                                    MsgBox (LogText2)
                                    For G = 1 To Len(LogText2) Step 1
                                        TheChar = Mid$(LogText2, G, 10)
                                        If TheChar = "Time Left:" Then
                                            MsgBox (TheChar)
                                            Exit For
                                        End If
                                    Next
                                    Call SendMessage(hWndTextbox, WM_SETTEXT, 0, "The time left is " & Mid$(LogText2, G, 12))
                                    Call PostMessage(hWndTextbox, WM_KEYDOWN, VK_RETURN, 0)
                                    Sleep (100)
                                End If
                            End If
                        End If
                    End If
                   
                       
                    'Kill Messages ################################################
                    If chkKillMessages.Value = 1 Then
                        If (InStr(1, LogText, " killed ", vbTextCompare) > 0) And (InStr(1, LogText, " with ", vbTextCompare) > 0) And (InStr(1, LogText, ":", vbTextCompare) < 1) And (InStr(1, LogText, "self", vbTextCompare) < 1) Then
                            'Get the first part
                            Pos1 = InStr(1, LogText, " killed ", vbTextCompare)
                            Player1 = Left$(LogText, Pos1)
                            Pos2 = InStr(1, Player1, "(#", vbTextCompare)
                            Player1 = Left$(LogText, Pos2 - 1)
                           
                            Pos1 = InStr(1, LogText, " killed ", vbTextCompare)
                            Pos3 = Pos1 + 8
                            Pos2 = InStr(Pos3, LogText, "(#", vbTextCompare)
                            Player2 = Mid$(LogText, Pos3, Pos2 - Pos3)
                            RandomInt = Int((6 - 1 + 1) * Rnd) + 1
                            Select Case RandomInt
                                Case 1
                                    Message = Player2 & " just got RickRoll'd."
                                Case 2
                                    Message = Player2 & " ate " & Player1 & "'s bullets!"
                                Case 3
                                    Message = Player1 & " showed " & Player2 & " Hammer Time xD"
                                Case 4
                                    Message = Player2 & " got BANHAMMER'd."
                                Case 5
                                    Message = Player2 & " try next time, if there is one..."
                                Case 6
                                    Message = Player1 & " > " & Player2 & "."
                            End Select
                            'MsgBox (RandomInt)
                            'MsgBox (Message)
                            Call SendMessage(hWndTextbox, WM_SETTEXT, 0, Message)
                            Call PostMessage(hWndTextbox, WM_KEYDOWN, VK_RETURN, 0)
                            Sleep (100)
                           
                        End If
                    End If
                   'Clear Server and add it to the programs log
                   'Grab the new log :P
                   lSize = SendMessage(hWndOutbox, WM_GETTEXTLENGTH, 0&, ByVal 0&)
                   If lSize > 0 Then
                    sBuf = String(lSize + 2, " ")
                    lRet = SendMessage(hWndOutbox, WM_GETTEXT, ByVal lSize + 1, ByVal sBuf)
                    If lRet > 0 Then
                        LogText = Left$(sBuf, lSize + 2)
                    End If
                   End If
                   
                   txtLog.Text = txtLog.Text & LogText
                   Sleep (200)
                   Call SendMessage(hWndOutbox, WM_SETTEXT, 0, "")
                Else
                    MsgBox ("Error while attempting to retrieve log text. The server window may not be open or you may have not of searched for it.")
                End If
            End If
           
            txtLog.SelStart = Len(txtLog.Text)
           
           
        Loop Until keep_inject = 0

Now, this is inefficient. What this is supposed to do is get the text from program B, process it, and set the text of the other program B to null. I set it to null so I can process one line at a time. There are a lot of sleeps, the main reason is because when I send a message then post the enter key, it doesn't work half of the time, so I make sure by sleeping for a bit...

Please tell me if there is a more efficient way.
Title: Re: Programming Q&A
Post by: Rukiri on December 20, 2008, 11:56:18 pm
Does anyone know how to create huds in C#/XNA? I know how to draw the images but not so code them, I'm sure I can code a number based hud system. Can't code a heart engine or a meter based hud yet.
Title: Re: Programming Q&A
Post by: Cassyblanca on December 21, 2008, 12:01:47 am
In the world of C#, it depends on how you've set up your system, and how much you know and can learn. I could whip up a quick, general mini-tutorial for you, if you are interested.

I warn you, though, when I write tutorials, I explain things and expect you to learn what I'm teaching you to do, rather than you just taking the system and throwing it in without learning any of it. I want you to understand why I do things the way I do.
Title: Re: Programming Q&A
Post by: Rukiri on December 21, 2008, 01:35:25 am
It's not that I don't understand, I just dunno how, I'd appreciate it if you did though^^
Title: Re: Programming Q&A
Post by: Cassyblanca on December 21, 2008, 01:53:24 am
About half-way done (I started on it earlier). I'll finish it and upload it after I'm done playing TFU
Title: Re: Programming Q&A
Post by: Rukiri on December 21, 2008, 03:52:23 am
Awesome thanks, this will be a huge help, I'll learn soo much from it^^
Title: Re: Programming Q&A
Post by: Cassyblanca on December 21, 2008, 04:17:12 am
Created. I've posted it in the Tutorials board.

http://www.zfgc.com/forum/index.php?topic=32778.0
Title: Re: Programming Q&A
Post by: Xiphirx on January 03, 2009, 01:08:01 am
Say I have a ListBox in one program, and I want to get the List from that, convert it to a string, and put it in a text box in my program.

I have tried to get the ListBox's List:
Code: [Select]
hWndPlayers = FindWindowEx(hWndServer, 0&, "WindowsForms10.LISTBOX.app.0.378734a", vbNullString)
Yes this is VB

But, hWndPlayers returns 0... The class name is correct (I used WinSpy ++ 1.7). What could be going on?
Title: Re: Programming Q&A
Post by: ZeldaPwns on March 02, 2009, 04:44:30 pm
I'm just starting out in using game maker. I just downloaded game maker 7 and I want to learn how to make a zelda engine from scratch. What do I do :huh:
Title: Re: Programming Q&A
Post by: TheDarkJay on March 02, 2009, 04:58:17 pm
I'm just starting out in using game maker. I just downloaded game maker 7 and I want to learn how to make a zelda engine from scratch. What do I do :huh:

A part of me really hopes this is a troll... Say you want to learn a language. Not a programming language, a real one. Like French or German or Japanese. You start off with the basics, learn how to introduce yourself, how the words fit together. Then you start to form basic sentances, and so-on.

Learning a programming language is very similar. You learn the basics, what commands do and mean what, how the syntax is organised (if it's not drag & drop) and so-on. You read about the basics, and use them to form sentances, or small programs as is the case. Then you use this acquired knowledge to learn and understand more, until you know enough to effectively communicate in the language, or in the case of programming/dragging-and-dropping-pansy-game-maker-work effectively get a developed and function program up and running.

TL:DR version: Read the tutorials, learn the basics and apply them.
Title: Re: Programming Q&A
Post by: Xavier on March 02, 2009, 05:03:20 pm
You should start by downloading some Game Maker examples and study them, here are a bunch you can download (http://www.kousougames.com/examples.php). You could read the help file of Game Maker too, it really helps when you don't know how this or that function works. Game Maker has got an official forum too, there you can get help and you can find lots of tutorials. And finally I think you can ask for help on this forum, I know there are a bunch of people who use Game Maker here.
Title: Re: Programming Q&A
Post by: TheDarkJay on March 02, 2009, 09:46:23 pm
I seem to be having an odd C++ linker error. It's probably something simple...

I have a singleton template class. Now, obviously this contains a static templated pointer. This needs to be declared, so I do this in a special cpp file, ISingleton.hpp.

Now, if I do a full-on templated declaration of:
template <class T> T* DOM::System::Tools::ISingleton<T>::_pv_singleton = 0;

I get compile-time errors of undefined references to _pv_singleton. Now, if I do this in main.cpp instead of ISingleton.cpp, it compiles and executes without complaint. Similarily, if I specialise the class in ISingleton.cpp, say:

template <> int* DOM::System::Tools::ISingleton<int>::_pv_singleton = 0;

and then create a singleton of type ISingleton<int>, this also compiles fine.

Anybody got any idea why this is screwing with me like this? :)
Title: Re: Programming Q&A
Post by: MG-Zero on March 02, 2009, 11:07:54 pm
Try making it static?  What does the error read?
Title: Re: Programming Q&A
Post by: TheDarkJay on March 02, 2009, 11:15:25 pm
Try making it static?  What does the error read?

make what static? The pointer in the class is static <_<

Error is just
obj\Debug\CODE\src\main.o||In function `ZN3DOM6System5Tools10ISingletonIfE11getInstanceEv':|
::Create()]+0x1d)||undefined reference to `DOM::System::Tools::ISingleton<float>::_pv_singleton'|
::getInstance()]+0x8)||undefined reference to `DOM::System::Tools::ISingleton<float>::_pv_singleton'|
::getInstance()]+0x15)||undefined reference to `DOM::System::Tools::ISingleton<float>::_pv_singleton'|
::Delete()]+0x8)||undefined reference to `DOM::System::Tools::ISingleton<float>::_pv_singleton'|
::Delete()]+0x12)||undefined reference to `DOM::System::Tools::ISingleton<float>::_pv_singleton'|
||=== Build finished: 5 errors, 0 warnings ===|
Title: Re: Programming Q&A
Post by: TheDarkJay on March 16, 2009, 07:09:34 pm
Turns out the problem is with how C++ compilers link together CPP files. They remaie aware of template specialisation but not of the more abstract version. I created a define macro which allows for specialisation easily in CPP files and left it at that, seems like a good approach in the end when I think of it, since I create templates with the likelyhood of them being specialised for certain uses in mind (policy based design has me by the balls).
Title: Re: Programming Q&A
Post by: Xiphirx on March 21, 2009, 12:47:41 am
- Removed. I'm dumb.
Title: Re: Programming Q&A
Post by: Xiphirx on April 11, 2009, 09:25:32 pm
What is wrong with this?

Code: [Select]
//Everything is good, update the database
$query = "UPDATE news SET title = ".$newstitle.", post = ".$newspost.", date = ".$date." WHERE id = ".$id." LIMIT 1 ";
$result = $connector->query($query);

if ($result==1)
{
header("location:index.php");
}
else
{
$error = "Error, could not insert into database!".$result.$id."";
header("location: index.php?action=error&message=".$error."");
}

I always get the error message "Error, could not insert into database!"...

I have triple checked the query and the actual table.
Title: Re: Programming Q&A
Post by: Infinitus on April 11, 2009, 09:41:23 pm
Not sure off hand. I usually use mysql manually, I don't use proxy objects.

However the things I would recommend checking is both that the result returns 1 on true (usually its 0 if successfull). And I would also quote all the strings in your query, as well as escape any quotation marks within the values to prevent sql injection.

eg.

Code: [Select]
$query = "UPDATE news SET title = '".addslashes($newstitle)."', post = '".addslashes($newspost)."', date = ".$date." WHERE id = ".$id." LIMIT 1 ";
Title: Re: Programming Q&A
Post by: Xiphirx on April 11, 2009, 09:45:07 pm
Not sure off hand. I usually use mysql manually, I don't use proxy objects.

However the things I would recommend checking is both that the result returns 1 on true (usually its 0 if successfull). And I would also quote all the strings in your query, as well as escape any quotation marks within the values to prevent sql injection.

eg.

Code: [Select]
$query = "UPDATE news SET title = '".addslashes($newstitle)."', post = '".addslashes($newspost)."', date = ".$date." WHERE id = ".$id." LIMIT 1 ";


$result is returning nothing for some reason.
Code: [Select]
$error = "Error, could not insert into database!".$result.$id."";

For example, would display as "Error, could not insert into database!20"; 20 is the id, so the result = ""...
Title: Re: Programming Q&A
Post by: AcidGame on April 12, 2009, 02:17:52 am
Assuming that $connector is a PDO object... Try this instead:
Code: [Select]
//Everything is good, update the database
$query = "UPDATE news SET title = ".$newstitle.", post = ".$newspost.", date = ".$date." WHERE id = ".$id." LIMIT 1 ";
$result = $connector->exec($query);

if ($result==1)
{
header("location:index.php");
}
else
{
$error = "Error, could not insert into database!".$result.$id."";
header("location: index.php?action=error&message=".$error."");
}
Title: Re: Programming Q&A
Post by: Xiphirx on April 12, 2009, 02:51:21 am
No no, I figured it out. Apparently it wanted single quotes around the values and no quotes around the field names : /

Btw, Connector is a class (lol my first ever php class).
Title: Re: Programming Q&A
Post by: Xiphirx on April 17, 2009, 11:48:55 pm
Sorry for double posting, but it seems like no one else is using this topic :P

Is there any motion path system in Blitzmax? Anyone know how I can implement it?
Title: Re: Programming Q&A
Post by: Infinitus on April 17, 2009, 11:55:34 pm
No there isn't a built in one. Its something that would normally built on a the higher-level game engine, its not something that would be built into a language. Its not exactly hard to do though, try writing your own.
Title: Re: Programming Q&A
Post by: Xiphirx on April 18, 2009, 12:27:11 am
No there isn't a built in one. Its something that would normally built on a the higher-level game engine, its not something that would be built into a language. Its not exactly hard to do though, try writing your own.

Do you know of any ones already made? I am using this for the competition and I don't exactly have the time.
Title: Re: Programming Q&A
Post by: Infinitus on April 18, 2009, 12:54:29 am
No. As I said, the system is not exactly hard to build, nor that time consuming. I doubt anyone has made a module specifically for it.
Title: Re: Programming Q&A
Post by: Xiphirx on April 18, 2009, 01:19:26 am
No. As I said, the system is not exactly hard to build, nor that time consuming. I doubt anyone has made a module specifically for it.

*starts to think about algorithms*
Title: Re: Programming Q&A
Post by: MG-Zero on April 18, 2009, 05:36:29 am
Regarding hitboxes in C++, what would be the fastest way to check if the player is colliding with one of them?  Say, there's 20 hitboxes, basically how could I quickly check if the player is colliding with one of them?  The hitboxes are instances of a class called CHitBox and a collision is detected through a function that returns true or false based on where the two hitboxes being checked are located in relation to one another.
Title: Re: Programming Q&A
Post by: Infinitus on April 18, 2009, 12:34:06 pm
Regarding hitboxes in C++, what would be the fastest way to check if the player is colliding with one of them?  Say, there's 20 hitboxes, basically how could I quickly check if the player is colliding with one of them?  The hitboxes are instances of a class called CHitBox and a collision is detected through a function that returns true or false based on where the two hitboxes being checked are located in relation to one another.
There are all kinds of intresting ways to deal with collision detection, it really depends on the effort you want to put in and how badly you want to optimize it. You could do the simple route of just iterating through all objects and testing the players hitbox against the objects hitbox, and returning a collision if any exist. Or if you want you could build up a quadtree or a similar data structure and limit all collision detection to hit boxes within the leaf of the tree that the player is in. Its really up to you. For the majority of the time though, simply interating through a list will be more than fine, especially when you only have 10 or so.
Title: Re: Programming Q&A
Post by: MG-Zero on April 18, 2009, 03:23:41 pm
Well, 10 was only an example, I expect to have a lot more than that.  But, considering how my collision algorithm works, I don't think it will take too much time to iterate through a list.  Thanks, I'll see what I can do.
Title: Re: Programming Q&A
Post by: Xiphirx on May 12, 2009, 03:33:14 am
Is there something I should know about the SendMessage API function and VB 2005? It doesn't want to work for me at all :|

Declaration:
Code: [Select]
Declare Function SendMessage Lib "USER32" Alias "SendMessageA" ( _
        ByVal hWnd As Long, ByVal Msg As Long, _
    ByVal wParam As Integer, ByVal lParam As String) As Long

Usage:
Code: [Select]
Call SendMessage(hWndTextbox, WM_SETTEXT, 0, "--- XMX MOD ---")


The odd thing is that the code worked perfectly in VB 6 :|
Title: Re: Programming Q&A
Post by: MG-Zero on May 12, 2009, 05:44:07 am
What's the error that you're getting?  I don't think you need that call command in there..
Title: Re: Programming Q&A
Post by: Xiphirx on May 12, 2009, 03:53:12 pm
What's the error that you're getting?  I don't think you need that call command in there..

-- Fixed
Title: Re: Programming Q&A
Post by: MG-Zero on May 24, 2009, 04:43:27 am
How can I read the data from a comma delimited file with C++?  I've got a VB program that outputs data like this to a file, for example:

-1, -1, 0, 5, 6, 4, 3, 3, 3, 3, 3 , 1, 25, 30, 99, 80, 5, "Player", 10, 12

(just made some numbers up..)

How could I read these into a C++ program?  I'm not really too familiar with file I/O in this language.

Title: Re: Programming Q&A
Post by: TheDarkJay on May 24, 2009, 09:04:24 am
well you could go through it byte by byte appending to a string as you go until you hit the end of file or a comma,
then convert the string to an integer value...

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved