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 / Text adventure combat function bug

Author
Message
Omnomer
13
Years of Service
User Offline
Joined: 12th Mar 2011
Location: a goauld mothership
Posted: 22nd Mar 2011 02:37
In the text adventure I'm making I have a function (below) but any text to be printed or input comands within my function don't happen. Can anyone explain why?
Function easycombat()


Mwahahahahahahahahahahahahaha
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 22nd Mar 2011 05:44
For starters, have a look at the "Select Case" commands. It'll save you writing half a dozen if statements.

If you're aware of the "Select Case" commands, is there a reason as to why you're not using them?

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 22nd Mar 2011 06:28 Edited at: 22nd Mar 2011 06:55
In keeping with BFM's tradition of not answering your question...

Did you know that "Rouge" is "a cosmetic used to color the cheeks and emphasize the cheekbones"? You probably mean "Rogue" though.

Kidding aside, it's hard to say why your function is not printing or accepting input, without seeing the rest (or part of the rest) of your code.

Some questions do come to mind though...

Is Class$ declared as a global? If not, then all your IF/THEN tests will fail, as Class$ will always equal an empty string. That's where BFM's suggestion of using SELECT/CASE can be quite handy. A simple CASE DEFAULT would catch any value for Class$ that is not specifically tested.

Thus:



Also, the variable "HP" should be global, so that it persists through calling the easycombat() function.

Of course there could be some other problem. Are you using sync commands? Have you changed the ink color? And so on...

Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 22nd Mar 2011 06:58
Too funny Rich.

I'm in the middle of an Autodesk bootcamp, so it's a little difficult to pull apart code in my half hour lunch break.

When I was first learning about functions, I found the easiest way to troubleshoot them was by moving my failing function code out from the failing function and into my main loop. Often you'll find it's simply a non-global variable being assumed as global by the programmer to be causing the problem.

Specifically though, in the code example provided in Omnomer's original post, I think it's the "ExitFunction" commands that are killing his function. I've been taught not to code using the "ExitFunction" command.

It's all about Sequence, Selection & Iteration.

Basically, every time a DBpro coder uses ExitFunction, a glitch in the Matrix kills a kitten.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 22nd Mar 2011 08:40 Edited at: 22nd Mar 2011 08:45
Quote: "Basically, every time a DBpro coder uses ExitFunction, a glitch in the Matrix kills a kitten."


LOL!

I don't think he ever reaches the exitfunction command, my gut feeling is that Class$ is local, and none if the IF tests pass. When I declare Class$ as global and assign it "Fighter" the function works well enough.

But I could be wrong...



Omnomer
13
Years of Service
User Offline
Joined: 12th Mar 2011
Location: a goauld mothership
Posted: 23rd Mar 2011 01:46 Edited at: 23rd Mar 2011 01:54
Wow thanks for the quick response. You fixed my code. The problem was the local/global issue
Burning Feet Man: I didn't know about the select case comand I'll look into it though.
Rich Dersheimer: No I didn't know I was spelling rogue wrong. I thought Class was local but I guess not so I changed that too. Here's the rest of my game code and yess I know it is "spagietycode" but don't comment on that.



Mwahahahahahahahahahahahahaha
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 23rd Mar 2011 02:32
Ok, definitely go read up on Select Case before progressing with your project. Then employ it in your current code as a way of learning.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Omnomer
13
Years of Service
User Offline
Joined: 12th Mar 2011
Location: a goauld mothership
Posted: 23rd Mar 2011 05:43
Um BFM isn't the select case command almost EXACTLY like the Ifs i've been using? No offense ment

Mwahahahahahahahahahahahahaha
Burning Feet Man
16
Years of Service
User Offline
Joined: 4th Jan 2008
Location: Sydney, Australia
Posted: 23rd Mar 2011 08:33
Well, you know what they say... You can hammer a nail in by using a spanner. It's all about using the right tool for the job.

Help build an online DarkBASIC Professional help archive.
DarkBasic Help Wikia
Omnomer
13
Years of Service
User Offline
Joined: 12th Mar 2011
Location: a goauld mothership
Posted: 23rd Mar 2011 19:54
Nobody says that

Mwahahahahahahahahahahahahaha

Login to post a reply

Server time is: 2024-11-22 23:27:46
Your offset time is: 2024-11-22 23:27:46