ehm. It would break you out of the current loop.Zitat:
Zitat von psphacker12.
It would only restart the game if you had a loop from the start of the game that ended after the current loop or if you called a function after the loop you break out of.
Printable View
ehm. It would break you out of the current loop.Zitat:
Zitat von psphacker12.
It would only restart the game if you had a loop from the start of the game that ended after the current loop or if you called a function after the loop you break out of.
A sceKernelExitGame(); call would exit the game.
ok thx.:tup:Zitat:
Zitat von waterbottle
-= Double Post =-
it says rn1(undeclared???Code:#include <pspdisplay.h>
#include <pspgu.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <png.h>
#include "graphics.h"
#define printf pspDebugScreenPrintf
#define dprint pspDebugScreenPrintf
#define true 1
#define false !true
#define bool int
PSP_MODULE_INFO("???", 0, 1, 1);
//Standard callbacks
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int i;
int rn0 = (NULL);
int rn1 = (NULL);
int rn2 = (NULL);
bool status = (NULL);
int nums() {
SceCtrlData pad;
sceCtrlPeekBufferPositive(&pad, 1);
srand(sceKernelLibcTime(NULL));
if (rn0 != (NULL) & rn1 != (NULL) & rn2 != (NULL)) {
rn0=0
rn1=0
rn2=0
}
if (pad.Buttons != 0){
if(pad.Buttons & PSP_CTRL_CROSS) {
rn0=rand()%3;
rn0=rand()%3;
rn0=rand()%3;
}
}
if (rn0 != 3 & rn1 != 3 & rn2 !=3) {
pspDebugScreenSetXY(0,2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("You won./n");
pspDebugScreenPrintf("Press 'X' to restart./n");
if(pad.Buttons & PSP_CTRL_CROSS) {
nums();
}
}
if(rn0 != 0 & rn1 != 0 & rn2 != 0) {
pspDebugScreenSetXY(0,2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("Press 'X' to start");
} else {
if (pad.Buttons & PSP_CTRL_CROSS) {
pspDebugScreenSetXY(0, 2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("Generated Integer:%d/n",rn0);
pspDebugScreenPrintf("Generated Integer:%d/n",rn1);
pspDebugScreenPrintf("Generated Integer:%d/n",rn2);
sceDisplayWaitVblankStart();
sceKernelSleepThread();
}
}
}
int main(void) {
//main functions
pspDebugScreenInit();
SetupCallbacks();
while (1) {
//while loop
nums();
}
return 0;
}
how can i fix this?
By declaring m1 maybe??
It would help if you told us the line number.
Hi guys i just went to the book store today and saw a book called "C++ For Dummies" I looked through it and it seemed to have a lot of C++ information and it even came with a cd with a compiler and some other useful stuff. So I bought it. Havent started reading it yet but has anyone else gotten this book and was it helpful?
Usually the "___ for dummies" series have good informataion, but they are very generic. I wouldn't og bought that book myself, but it can't hurt to read it ;)
okay. but skimming through it it looks pretty good so i will read it anyways and i guess i read some internet tutorials too. thanks
Handling data recieved via TCP
Hi,
On a simple server I'm recieving (and displaying) a string via
but he outputs the string and the time it was recieved. What I want is to fetch the string (isolated) and save it in a variable. How do I do that?Code:for (;;) {
len = sizeof(client);
fd = accept(sock, (struct sockaddr*)&client, &len);
if (fd < 0)
error_exit("Fehler bei accept");
printf("Bearbeite Client mit der Adresse: %s\n", inet_ntoa(client.sin_addr));
/* Daten vom Client auf dem Bildschirm ausgeben */
echo ( fd );
closesocket(fd);
}
i have it set up like this..Zitat:
Zitat von homer
Code:int rn1 = (NULL);
In the case that you are using it, && is supposed to be used for 'and' statements, not &. You're also missing some semicolons.Zitat:
Zitat von psphacker12.
Solution:Zitat:
Zitat von Lukeson
What's the right returntype for char[256]?Code:for (;;) {
len = sizeof(client);
fd = accept(sock, (struct sockaddr*)&client, &len);
if (fd < 0)
error_exit("Error while accepting");
printf("Accepting connection, IP: %s\n", inet_ntoa(client.sin_addr));
while(rc!=SOCKET_ERROR)
{
rc=recv(fd,buf,256,0);
if(rc==0)
{
printf("Server has closed the connection...\n");
break;
}
if(rc==SOCKET_ERROR)
{
printf("Fehler: recv, fehler code: %d\n",WSAGetLastError());
break;
}
buf[rc]='\0';
printf("Client sendet: %s\n",buf);
//sprintf(buf2,"Du mich auch %s",buf);
//rc=send(connectedSocket,buf2,strlen(buf2),0);
}
closesocket(fd);
Here's another question:
I need to write a function that returns a string of variable length; in fact it's not a string, it's an array of "char"s; What return-type do I have t choose?
Lukeson - What? A 'char' datatype is a character array, or 'buffer'. If you're writing a function returning a char, then have the data type of that function, a char.
As for getting hte length of a given string, either include string.h (or stdlib..hmmm... cant rememmber) and use 'strlen(string)' or:
But i prefer you use the strnlen version, to prevent an overflow. Manual strnlen:Code:int
strlen(const char *s)
{
const char *sc;
for (sc = s; *sc != '\0'; ++sc)
;// nothing
return sc - s;
}
So say if you wanted to do a directory listing type thing, the psp screen only hold around 60 characters from left to right, so you may want to limit it.. By using strnlen, you can say only print the filename up to 60... Itd be much more complicated than that, but you really should use strnlen as it prevents an overflow.Code:int
strnlen(const char *s, int count)
{
const char *sc;
for (sc = s; count-- && *sc != '\0'; ++sc)
/* nothing */ ;
return sc - s;
}
Hmm I would reccomend to start out with that book, then later on you can learn the PSP specific syscalls.:)Zitat:
Zitat von GuitarGod1134
Yes cause everyone needs to know them in order to create for hte PSP. =-\ [/sarcasm]
I'm sorry, I'm stupid and don't get it;
So a char isn't - as I thought - a single character but a buffer for a string? so can I just do this:?
Tested, freezes the PSPCode:char foo()
{
char buf[256];
buf = get_string_from_server();
return buf;
}
int main()
{
...
printf("%s", foo());
...
}
I probably need to clarify my question; I have a function that recieves a string via recv() from the server. I want this string to be the return-value of the function, I just don't know what return-type i need therefor. Ex.:
Code:[???] get_artists(int socket)
{
long rc;
char buf[256];
...
rc=recv(socket,buf,256,0);
buf[rc]='\0';
return buf;
}
BTW who was that guy who released the tiff game "BRICKS" without your permission? and how did he get his hands onto it?Zitat:
Zitat von SG57
-= Double Post =-
not working
ErrorsCode:#include <pspdisplay.h>
#include <pspgu.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <png.h>
#include "graphics.h"
#define printf pspDebugScreenPrintf
#define dprint pspDebugScreenPrintf
#define true 1
#define false !true
#define bool int
PSP_MODULE_INFO("???", 0, 1, 1);
//Standard callbacks
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int funcs() {
int i;
int rn0 = (NULL);
int rn1 = (NULL);
int rn2 = (NULL);
bool status = (NULL);
SceCtrlData pad;
sceCtrlPeekBufferPositive(&pad, 1);
srand(sceKernelLibcTime(NULL));
}
int nums() {
if (rn0 != (NULL) && rn1 != (NULL) && rn2 != (NULL)) {
rn0=0
rn1=0
rn2=0
}
if (pad.Buttons != 0){
if(pad.Buttons && PSP_CTRL_CROSS) {
rn0=rand()%3;
rn1=rand()%3;
rn2=rand()%3;
}
}
if (rn0 != 2 && rn1 != 2 && rn2 != 2) {
pspDebugScreenSetXY(0,2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("You won./n");
pspDebugScreenPrintf("Press 'X' to restart./n");
}
if (rn0 != 3 && rn1 != 3 && rn2 !=3) {
pspDebugScreenSetXY(0,2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("You won./n");
pspDebugScreenPrintf("Press 'X' to restart./n");
if(pad.Buttons & PSP_CTRL_CROSS) {
nums();
}
}
if(rn0 != 0 && rn1 != 0 && rn2 != 0) {
pspDebugScreenSetXY(0,2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("Press 'X' to start/n");
} else {
if (pad.Buttons && PSP_CTRL_CROSS) {
pspDebugScreenSetXY(0, 2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("Generated Integer:%d/n",rn0);
pspDebugScreenPrintf("Generated Integer:%d/n",rn1);
pspDebugScreenPrintf("Generated Integer:%d/n",rn2);
sceDisplayWaitVblankStart();
sceKernelSleepThread();
}
}
}
int main(void) {
//main functions
pspDebugScreenInit();
SetupCallbacks();
while(1) {
//while loop
funcs();
nums();
}
return 0;
}
Code:[email protected] ~
$ cd /pspdev
[email protected] /pspdev
$ make
psp-gcc -I. -I/usr/psp/sdk/include -O2 -G0 -Wall -c -o main.o main.c
main.c : In function 'funcs':
main.c(50) : warning: initialization makes integer from pointer without a cast
main.c(51) : warning: initialization makes integer from pointer without a cast
main.c(52) : warning: initialization makes integer from pointer without a cast
main.c(53) : warning: initialization makes integer from pointer without a cast
main.c(53) : warning: unused variable 'status'
main.c(52) : warning: unused variable 'rn2'
main.c(51) : warning: unused variable 'rn1'
main.c(50) : warning: unused variable 'rn0'
main.c(49) : warning: unused variable 'i'
main.c : In function 'nums':
main.c(59) : error: 'rn0' undeclared (first use in this function)
main.c(59) : error: (Each undeclared identifier is reported only once
main.c(59) : error: for each function it appears in.)
main.c(59) : error: 'rn1' undeclared (first use in this function)
main.c(59) : error: 'rn2' undeclared (first use in this function)
main.c(61) : error: syntax error before 'rn1'
main.c(64) : error: 'pad' undeclared (first use in this function)
make: *** [main.o] Error 1
[email protected] /pspdev
$
GuitarGod1134:
Don't get that book, they are usually pretty poor in my opinion.
Take a read through this online book:
http://www.ibiblio.org/obp/thinkCS/cpp/english/
And consider buying this one:
http://www.amazon.co.uk/gp/product/1...649123-1896422
Lukeson:
The correct return type would be a char pointer:Code:[???] get_artists(int socket)
{
long rc;
char buf[256];
...
rc=recv(socket,buf,256,0);
buf[rc]='\0';
return buf;
}
However this will throw a runtime error:Code:char * get_artists(int socket)
{
long rc;
char buf[256];
...
rc=recv(socket,buf,256,0);
buf[rc]='\0';
return buf;
}
This is because the buf that was in the function was created locally on the stack and the function returns a pointer to it. However, after the pointer assignment to buffer, it is removed from the stack since it is no longer in scope and now pointer is pointing to garbarge. A better method would be to do:Code:char buffer[256];
buffer = get_artists(6666);
printf("%s", buffer);
-= Double Post =-Code:void get_artists(int socket, char * recivedMessage)
{
long rc;
...
rc=recv(socket,recivedMessage,256,0);
recivedMessage[rc]='\0';
return recivedMessage;
}
int main()
{
char buffer[256] = "";
get_artists(6666, buffer);
printf("%s", buffer);
...
}
psphacker12.:
You are assigning non pointer variables NULL. NULL is usually #defined as 0 and should be reserved for pointers only hence a warning rather then an error. Just give them the value 0.Code:main.c(50) : warning: initialization makes integer from pointer without a cast
main.c(51) : warning: initialization makes integer from pointer without a cast
main.c(52) : warning: initialization makes integer from pointer without a cast
main.c(53) : warning: initialization makes integer from pointer without a cast
Code:int rn0 = 0;
int rn1 = 0;
int rn2 = 0;
You didn't use any of the variables in the function funcs().Code:main.c(53) : warning: unused variable 'status'
main.c(52) : warning: unused variable 'rn2'
main.c(51) : warning: unused variable 'rn1'
main.c(50) : warning: unused variable 'rn0'
main.c(49) : warning: unused variable 'i'
None of these variables have been decleared in scope of the function nums().Code:main.c : In function 'nums':
main.c(59) : error: 'rn0' undeclared (first use in this function)
main.c(59) : error: (Each undeclared identifier is reported only once
main.c(59) : error: for each function it appears in.)
main.c(59) : error: 'rn1' undeclared (first use in this function)
main.c(59) : error: 'rn2' undeclared (first use in this function)
main.c(64) : error: 'pad' undeclared (first use in this function)
You forgot ';' on the line before.Code:main.c(61) : error: syntax error before 'rn1'
How can I fix that?Zitat:
None of these variables have been decleared in scope of the function nums().
You forgot ';' on the line before.Code:main.c(61) : error: syntax error before 'rn1'
Great idea, quote the entire post for one small part of it (-_-;)
Code:int nums() {
if (rn0 != (NULL) && rn1 != (NULL) && rn2 != (NULL)) {
rn0=0
rn1=0
rn2=0
}
Here is another tip, buy this book:Code:int nums() {
int rn0=0;
int rn1=0;
int rn2=0;
SceCtrlData pad;
The C programming Language or this one Beginning C++ Game Programming or at LEAST read this online one: Thinking like a computer scientist [C++]
http://forums.qj.net/user_pics/38805-1158412981.gifZitat:
Zitat von psphacker12.
add a ; to the end of the last line.
I've been looking over "Thinking like a computer scientist [C++]" and I was wondering should I use cout<< or printf??Zitat:
Zitat von head_54us
Use printf. Getting the STL library to work with the PSP compiler is a bit of work.
couldnt i just do this??Zitat:
Zitat von head_54us
or would that give me an error?Code:int nums() {
funcs();
im trying it now. :)
You are just calling the function. It will still give the same error. Read about variable scope.
That works, thank you!Zitat:
Zitat von head_54us
I believe the fist book you mentioned can be read for free here: http://www.fis.cinvestav.mx/~jccoron...guageAnsiC.pdfZitat:
Zitat von head_54us
when I press 'x' it doesnt update the info..Code:#include <pspdisplay.h>
#include <pspgu.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <png.h>
#include "graphics.h"
#define printf pspDebugScreenPrintf
#define dprint pspDebugScreenPrintf
#define true 1
#define false !true
#define bool int
#define NULL 0
PSP_MODULE_INFO("???", 0, 1, 1);
/* Standard callbacks */
int exit_callback(int arg1, int arg2, void *common) {
sceKernelExitGame();
return 0;
}
int CallbackThread(SceSize args, void *argp) {
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
int SetupCallbacks(void) {
int thid = 0;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0) {
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int nums() {
int rn0 = 0;
int rn1 = 0;
int rn2 = 0;
bool status = 0;
SceCtrlData pad;
sceCtrlPeekBufferPositive(&pad, 1);
srand(sceKernelLibcTime(NULL));
if (pad.Buttons != 0){
if(pad.Buttons && PSP_CTRL_CROSS) {
rn0=rand()%1,3;
rn1=rand()%1,3;
rn2=rand()%1,3;
}
}
if (rn0 == 1 && rn1 == 1 && rn2 == 1) {
pspDebugScreenSetXY(0,2);
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("You won.\n");
pspDebugScreenPrintf("Press 'X' to restart.\n");
if(pad.Buttons & PSP_CTRL_CROSS) {
nums();
}
}
if (rn0 == 2 && rn1 == 2 && rn2 == 2) {
pspDebugScreenSetXY(0,2);
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("You won.\n");
pspDebugScreenPrintf("Press 'X' to restart.\n");
if(pad.Buttons & PSP_CTRL_CROSS) {
nums();
}
}
if (rn0 == 3 && rn1 == 3 && rn2 ==3) {
pspDebugScreenSetXY(0,2);
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("You won.\n");
pspDebugScreenPrintf("Press 'X' to restart.\n");
if(pad.Buttons & PSP_CTRL_CROSS) {
nums();
}
}
if(rn0 == 0 && rn1 == 0 && rn2 == 0) {
pspDebugScreenSetXY(0,2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
pspDebugScreenPrintf("Press |`'~X~'`| to start\n");
if(pad.Buttons && PSP_CTRL_CROSS) {
pspDebugScreenSetXY(0,2);
pspDebugScreenClear();
pspDebugScreenSetBackColor(0x00FF0000);
pspDebugScreenSetTextColor(0x00000000);
rn0=rand()%1,3;
rn1=rand()%1,3;
rn2=rand()%1,3;
} }
}
int main(void) {
/* main functions */
pspDebugScreenInit();
SetupCallbacks();
while(true) {
/* while loop */
nums();
}
return 0;
}
Hey, sup guys? well I need help.
Im trying to change DevHook Launcher font with this guide: http://forums.qj.net/psp-development-forum/47934-release-flib-truetype-font-library-c.html
And its always dont working If someone can send me the DevHook Launcher SDK WITH ANY OTHER FONT And tell me where im chaging it again I would be very happy.
psphacker12: You have been told this many times:
&& - logical AND
& - Bitwise AND.
Bronx: That link looks VERY illegal.
How can I change which folder cygwin starts in?
for me it starts in 'home/my name'
but I wan't it to start in 'home/myname' tried renaming the my name folder to myname and then changing the name of my xp user to myname instead of my name.
but cygwin just created a new folder still.
Hey,
Anybody know if normal PC SDL is exactly the same as PSP SDL.
If not, whats the difference?
--Vaza
I believe so, haven't worked that much with it though.Zitat:
Zitat von Vaza
hah lol ur not prem anymoreZitat:
Zitat von homer
First of all, why would you laugh at him for not being premium? And second of all, yes he is. He just changed the color of his name.Zitat:
Zitat von psphacker12.
STFU you n00b.Zitat:
Zitat von psphacker12.
I am premium, I just changed the color to dark blue.
:Argh: sorry for laughing at youZitat:
Zitat von homer
The main differeces I know of is the control mapping and that a lot of SDL is done in software insteado hardware. The control mapping for SDL is all using a 'joystick' instead of buttons. Check out this thread: http://forums.ps2dev.org/viewtopic.p...49c129a3f2328fZitat:
Zitat von Vaza
@psphacker12, Homer still has a sig, he HAS to be premium/dev... Use your common sense nd stop spamming the forums
okay I successfully installed the freetype lib
but when I try to compile it gives me this.
http://i52.photobucket.com/albums/g9...wGIMPimage.jpg
Add flib.o to the OBJS line in your makefile.
You'll probably need graphics.o and framebuffer.o too.