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.

DarkBASIC Professional Discussion / DarkBASIC_Pro. Problem!!

Author
Message
Knights
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 18th Mar 2011 16:29
Hi, Im programming a game with a few friends and I cant seem to figure out how to take center text off the screen.For my game I would like to ask the player questions that way the game meets the criteria for my teacher. This is part of my code:

Center text 120,380, "1.5 is the _____of 25."
Center text 120,400, "a.Integer"
Center text 120,420, "b.Equation"
Center text 120,440, "c.Square root"
Center text 120,460, "d.Algebra"
If inkey$()="a"=1 then dec totalFuel,2000
If inkey$()="b"=1 then dec totalFuel,2000
If inkey$()="c"=1 then inc totalFuel,2000
If inkey$()="d"=1 then dec totalFuel,2000
If inkey$()="a"=1 then center text 520,390, "Sorry that is incorrect."
If inkey$()="b"=1 then center text 520,410, "Thats wrong.."
If inkey$()="c"=1 then center text 520,430, "Great job!! Keep it up."
If inkey$()="d"=1 then center text 520,450, "Try again later."

I would like to delete the center text so that I can post more text for the 2nd question in my game. I just cant figure it out please help!!
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 18th Mar 2011 17:34
For one thing, your crazy!

Don't write your game like that, you'll loose track, it'll be a nightmare to debug, it'll be very tedious to work with.

I suggest you make an array to hold all the questions and answers, maybe with a type...

So at the start of your program, make the type and array to hold the questions and answers:

Type questiontype
Q$ A$ B$ C$ D$
A B C D
Endtype
Dim Questions(100) as questiontype

That will make the type and array, to make handling your questions very easy. The Q$ part is the question itself, the A$ B$ etc are the answer text, and A B C etc are the values - so in your example C would be 2000, whilst A B and D would be -2000.

Make a function to organise the questions even more....

Function Add_Question(num,q$,a$,b$,c$,d$,a,b,c,d)
Questions(num).Q$=q$
Questions(num).A$=a$
Questions(num).B$=b$
Questions(num).C$=c$
Questions(num).D$=d$
Questions(num).A=a
Questions(num).B=b
Questions(num).C=c
Questions(num).D=d
Endfunction

So you can call that with a single line to add it to the array:

Add_Question(0,"1.5 is the ____ of 25?","Integer","Square Root","Mother","Algebra",-2000,-2000,2000,-2000)

Then to ask a question...

function Ask_Question(num)

CLS
Center text 120,380, Questions(num).Q$
Center text 120,400, "a."+Questions(num).A$
Center text 120,420, "b."+Questions(num).B$
Center text 120,440, "c."+Questions(num).C$
Center text 120,460, "d."+Questions(num).D$
Sync

Do
i$=upper$(inkey$())
If i$="A" then exitfunction Questions(num).A
If i$="B" then exitfunction Questions(num).B
If i$="C" then exitfunction Questions(num).C
If i$="D" then exitfunction Questions(num).D
Loop

endfunction


So that Ask_Question function will return the value you've stored in .A .B .C or .D, you could even have more than one right answer, or different values for answers... anyway let me know if you want an actual example, rather than my usual code rambling.

Health, Ammo, and bacon and eggs!
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 18th Mar 2011 19:33
I would do as Van B suggested but just to let you know you can do multiple things within an IF statement if you drop the THEN and add an ENDIF to close the IF statement.



Knights
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 21st Mar 2011 16:26
OMG.. Thank you so much Van B... I knew there was an easier way to code this stuff. The school only teaches so much Well thanks alot ill keep in touch incase I need anymore help. Your the bestest!!!
Knights
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 22nd Mar 2011 16:12
Hey. Van B I tried what you said and its not working... Can you gimme the example so I can see what I did wrong???
Knights
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 22nd Mar 2011 16:23 Edited at: 22nd Mar 2011 20:16
This is my code can anyone tell me what I did wrong????



Its not all my code just the part I changed.. I cant seem to figure out why its not working.
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 22nd Mar 2011 20:30 Edited at: 22nd Mar 2011 20:32
First, it's good that you're not using gotos. But, breaking from loops is not a great thing either. You should look into the repeat and while commands.

Secondly, I only skimmed. Don't post such large sections of code in the open like that! Use the code tags. Also, you have to give us a description of what's going on. Not just, 'Here look at this (huge) segment of code! What's going wrong?' There could be a million things that are going wrong. Just tell us what it's not doing right, or what errors the DBP debugger is giving you, and we would be happy to provide an answer.

Third, in your first post, you do realize that 5 is the square root of 25, right? 1.5 is the square root of 2.25. Haha.

[EDIT] Wait! I see... That's question 1. 5 is the _____ of 25. My bad. Haha. I thought it said 1.5.

If life were like a box of chocolates, I'd know what I would get... The one that got dropped on the floor and put back in the box.

Iye nehvur yoose spehl chehk, ahn mie tippyng izz fiyne.
Knights
15
Years of Service
User Offline
Joined: 18th Mar 2011
Location:
Posted: 23rd Mar 2011 16:18 Edited at: 23rd Mar 2011 23:06
Lol yeah I know 5 is the squar root of 25.. and the reason I didnt specify on the specific problem is because its the same problem as before I dont know how to fix it.. . The object of my game is for the player to anwser algebraic terminology quetions I can print one question on the screen but once I put it there I dont know how to take it off the screen. It really sucks to because my dealines coming up and ive been slacking off the whole semester using my mistakes as my excuse . However, I wanna make a really good game. Van B told me to use arrays but I have no clue what that is sooo I copied and pasted his examples into my code and REMed my old code (just incase I ever have to use it again). When I try to run the executable I get a pop up that says "ENDFUNCTION only accepts a single value or local variables on line 679".



This is the section of code it highlights in the red color ... Well im completly lost and all the help I can get would be greattt. Please fix my dilema.
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 23rd Mar 2011 20:28
Here's a little example...



Health, Ammo, and bacon and eggs!
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 23rd Mar 2011 23:07
@Knights,
Please use code tags - it takes only a few extra seconds. Plus I'm not going to fix yours any more - we'll just let everyone else throw complaints at you about it

Login to post a reply

Server time is: 2026-07-16 23:19:39
Your offset time is: 2026-07-16 23:19:39