the problem with coding?

Started by
16 comments, last by PGSCreativeDirector 12 years, 6 months ago
Hello there i have been coding for about 7-8 months maybe more and well my issue here is the lack of simplified information on what i need in few cases like for instance ill look at the SDL tutorials or wikis and it will mostly just show the code and not explain much about it in alot of cases expecting that im an expert and all this but what if im learning as i go and need to understand not everything just alittle bit more then what SDL is providing now this is a problem and this doesn't happen in just SDL theres many cases where iv seen this such as WxWidgets it has all this documentation but doesn't really simplify it down to newcomers and that is a big deal that should be noted

on another note i have situation

Heres my problem

im trying to make a area of my window area clickable and then when clicked it does what i want it to do

now how do i do that in SDL Event and how did you figure it out because im one of those people who look at things and are not shore if its the right way or anything and need calarfications otherwise i worry that im doing it wrong

this is the page im looking at at the moment http://www.libsdl.or...singevents.html i don't understand it :(
for example i dont understand how its used is it just like that and nothing else??

or is there something extra im missing i was thinking it had something to do with SDL Event unions so i made a typedef struct and have all these Uint variable declarations and i also Declared the Variables themself using what i presume is the SDL way of doing it like using Uint8 type and button and State and xy and then putting a object name SDL_MouseButtonEvent which i assume stores all those informations that you need to declare?? what?? do i need to create a Union? but i dont really get how it all works what is the required mindset to figure out this problem and the solution to the problem as well :(

im using OpenGL , SDL and C++
Advertisement
Tutorials and especially documentation pages can't explain everything every time. They have to assume you know at least the basics. To learn the language (C, C++) I recommend you read a book or take a course. If you encounter something you don't understand you can look it up separately.

With SDL I find this SDL Documentation useful to look things up. If you find a type or function you don't understand what it does, look it up before continue. SDL_Event is a type already defined by SDL.

In the page you have found there is an example how to handle SDL_MOUSEBUTTONDOWN events. Information about SDL_MOUSEBUTTONDOWN and SDL_MOUSEBUTTONUP events is stored in event.button which is of type SDL_MouseButtonEvent. event.button.x and event.button.y are the coordinates of the click. Use that information to test if the click is inside the clickable area and if it is do what you want to do.

In case you didn't know about it, Lazy Foo tutorials is a popular SDL tutorial. Lesson 9 describes mouse events but you should probably look through the previous lessons if you don't like surprises.

You should not be afraid of testing things on your own. You learn a lot by doing so. Don't be afraid of learning more than you need to know, knowledge is not heavy.
so basically let me just get an example can't be arsed to write it all out at this point

[font="monospace"]{[/font] SDL_Event event; [color="#0000FF"]while ( SDL_PollEvent(&event) ) { [color="#0000FF"]switch (event.type) { [color="#0000FF"]case SDL_MOUSEMOTION: printf("[color="#000000"]Mouse moved by %d,%d to (%d,%d)\n", event.motion.xrel, event.motion.yrel, event.motion.x, event.motion.y); break; [color="#0000FF"]case SDL_MOUSEBUTTONDOWN: printf("[color="#000000"]Mouse button %d pressed at (%d,%d)\n", event.button.button, event.button.x, event.button.y); break; [color="#0000FF"]case SDL_QUIT: exit(0); } }}
I create an event using SDL_EVENT as like a type then when I've done that depending on how i want the event to work I then set it like poll or wait or directly then make shore i set it too event name that i used to attach SDL_EVENT type with also i setup the event type and make it whatever button i need then after that i put : and within it i put whatever code i want? after all that i use the break keyword and then its done

thats how i've figured it out is this correct? is there anything else that can be done with events that im missing with this statement please do tell me
It's hard to understand what you are saying. Make a small program that handles mouse events and play around with it. See if it do what you expect it to do.
{
SDL_Event event;

SDL_WaitEvent(&event);

switch (event.type) {
case SDL_MOUSEBUTTONUP:
fprintf (stdout,"randomwording");

if (fprintf == false);
{
fprintf(stdout,"Not Working");
}

break;
case SDL_QUIT:
exit(0);
}
}


this is the event i've made and it wont do, won't put any text into the stdout txt file ;(

I think i need to specify the actual button that will be pressed down?? how do i do that??
It sounds like you aren't as comfortable with the basics of C++ to approach this. You must learn to walk before you can run.

As an aside, it is difficult to understand you because you write long, rambling sentences/paragraphs. This is one of your recent ones:

I create an event using SDL_EVENT as like a type then when I've done that depending on how i want the event to work I then set it like poll or wait or directly then make shore i set it too event name that i used to attach SDL_EVENT type with also i setup the event type and make it whatever button i need then after that i put : and within it i put whatever code i want? after all that i use the break keyword and then its done
[/quote]
Compare that with something like:

I create an event using SDL_EVENT as the type. Next, depending on how I want the event to work, I set it to poll or wait. I set it to the event name that I used to attach the SDL_EVENT type with. I set up the event type and make it whatever button I need. After that I put a colon and within it I put whatever code I want?

Finally I use the break keyword and it is done.
[/quote]
Shorter, simple sentences are easier for everyone to understand. Take care with grammar and spelling too.

I say this because communication is important, especially for aspiring programmers. If you cannot communicate clearly to intelligent humans (who can compensate for a degree of error), you're going to struggle getting the idiot compiler to understand! Put yourself in our shoes - what would you do if you have a choice between spending 5 minutes deciphering one question, and answering a different question that is clearly articulated.

My own communication skills have vastly improved due to the time I've spend on gamedev.net, reading clear writing and practising it myself.
wooot !!! the art of people who want me to do extra effort when i detest intensive effort ahh the joys :D i dont follow rules i break them aslong as no bad comes from it and this ant bad anuff because i know people can help ether way so there you go now can someone actually help me rather then giving me there thought of perception im hoping wooh gets back hes awesome at this stuff

im gunna get this answer otherwise ill be sitting there for hours struggling and i can pass this by asking forums ircs and reading in some cases
+1 for rip-off and I would like to add that this is EXACTLY what makes coding so much fun: you have to find the answers to your problems, they are not offered to you on a silver plate. Sometimes you do it by looking at the docs, sometimes looking at the code, sometimes you just try every possible crazy thing that comes in your head to go around a problem.
If all the answers were already there in tutorials this would become such a boring job!

EDIT: nevermind.. wasted time

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

If you want help with code, post a full program we can see.

For example:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>

#include "SDL.h"

int main(int, const char **)
{
std::srand(static_cast<unsigned>(std::time(NULL)));

if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
std::cerr << "Failed to initialise SDL: " << SDL_GetError() << '\n';
return 1;
}

std::atexit(&SDL_Quit);

SDL_Surface *screen = SDL_SetVideoMode(600, 600, 0, SDL_SWSURFACE);
if(!screen)
{
std::cerr << "Failed to set video mode: " << SDL_GetError() << '\n';
return 1;
}

Uint32 colour = 0;
int x = 0;
int y = 0;

bool running = true;
while(running)
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
if(event.type == SDL_QUIT)
{
running = false;
}
else if(event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE)
{
running = false;
}
else if(event.type == SDL_MOUSEBUTTONDOWN)
{
x = event.button.x;
y = event.button.y;

if(event.button.button == 1)
{
colour = SDL_MapRGB(screen->format, 0xff, 0x00, 0x00);
}
else if(event.button.button == 2)
{
colour = SDL_MapRGB(screen->format, 0x00, 0xff, 0x00);
}
else
{
colour = SDL_MapRGB(screen->format, 0x00, 0x00, 0xff);
}
}
}

SDL_FillRect(screen, NULL, 0);
SDL_Rect rect = {x, y,10, 10};
SDL_FillRect(screen, &rect, colour);
SDL_Flip(screen);
}

return 0;
}

Woot !!! the art of people who want me to do extra effort when i detest intensive effort ahh the joys
[/quote]
If that is your attitude I will not be helping you in future. Why should I invest effort to help you, if you cannot invest the (more minimal) effort required to post a clear question?


i dont follow rules i break them aslong as no bad comes from it and this ant bad anuff because i know people can help ether way so there you go now can someone actually help me rather then giving me there thought of perception im hoping wooh gets back hes awesome at this stuff
[/quote]
The rules exist for a reason: communication is easier when they are followed. I didn't respond to your original post because I didn't understand half of what you were trying to say.

This topic is closed to new replies.

Advertisement