Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Help with a function

Author
Message
weedeater bob
16
Years of Service
User Offline
Joined: 11th Mar 2008
Location:
Posted: 27th Jun 2008 04:22
In a game I'm working on, whenever I try to run it, a certain endfunction shows up as 'out of place'. If I erase the contents of the function, everything works.



What am I doing wrong?
HowDo
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 27th Jun 2008 14:37
your missing one or more endif's. you 7 if but only 3 endif's.

Dark Physics makes any hot drink go cold.
Erios
18
Years of Service
User Offline
Joined: 17th Jun 2006
Location:
Posted: 27th Jun 2008 19:34
That construct would definitely benefit from from a SELECT statement. General idea is like this:



Sorry I don't have time at the moment to go through your code and re-write the example given, but you can see the general layout of the command. It goes through each CASE and tests the value of the variable you are selecting. You can put two or more possible values on the same CASE, as seen with the 2nd and 3rd values. CASE DEFAULT is optional, and is similar to ELSE in an IF statement. This may take a little bit of re-writing of the logic to your code, but using it for situations like this can really make your code more clear, and cause less errors.
RedFlames
17
Years of Service
User Offline
Joined: 25th Aug 2007
Location: Germania
Posted: 27th Jun 2008 22:59
Quote: "That construct would definitely benefit from from a SELECT statement. General idea is like this:"

No... he isnt comparing ONE variable to different values, but DIFFERENT variables to the value "Empty".
But i dont think there is a "else if" command,it will be treated like an "else" and a new "if" which then misses an "endif"

So this...

should be this:


But i think the whole function could be simplified:

I didnt test it but it should do the same as your function, although i dont know if it really does what you expect it to do

weedeater bob
16
Years of Service
User Offline
Joined: 11th Mar 2008
Location:
Posted: 1st Jul 2008 05:27 Edited at: 1st Jul 2008 19:32
Ok, I have worked in your advice, and it's working better now, but there's still some problems. I'm going to post my entire code so far.



Alright, firstly, It's not having any trouble reading the save file, or initially creating it/writing it, but when I make a new file, although it shows up within the program, it never gets written to the save file. Any help?

EDIT: Fixed this problem, the saving works now.



Secondly, I was experiencing a problem with the main menu, where, as soon as you hit a key, it just zooms through everything to the end. For example, if you hit the down key, it would just fly down to the bottom choice.

To fix it, I wrote the keypressed function, but now there's a different problem. Whenever I hit something, I have to hit something else to make it happen. For instance, if I hit the down arrow key, nothing happens, but if I then hit a letter key, it then recognizes my down key. It's almost like there's a wait key in there. Run it and you'll see what I mean. I think the keypressed function is causing this but I'm not positive. Any help would be appreciated.

Login to post a reply

Server time is: 2024-09-27 16:26:42
Your offset time is: 2024-09-27 16:26:42