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 / DarkBASIC Pro Project has stopped working

Author
Message
cguy
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: In my Computer!
Posted: 31st Jul 2009 05:11
I'm trying to use functions more often and decided to try to make one so that if the word "stop" was found in any part of a users input, the program would end.


The idea was that the function would return a 1 if the word was found, but not only did thhat not happen, I got a message that said "DarkBASIC Pro Project has stopped working" and my program was forced to exit. Any help with this?

Do we all have to put stupid jokes here?
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 31st Jul 2009 05:15
I believe the font is "arial", not "ariel". That might crash it. If that isn't it, there's something wrong with the FIND SUB STRING$ command.



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
cguy
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: In my Computer!
Posted: 31st Jul 2009 05:45
You certainly are right about the font being "arial", but for some reason, it works if you type in "ariel". Huh...that's interesting. Anyway, that's not the problem. Like you said, the source of the problem is most likely line 17, with the FIND SUB STRING$ command. If you take it out, the program runs. If it was a syntax error on my part, though, the program would not have compiled at all. I'll tweak it a bit and see what happends. Thanks BMacZero!

Do we all have to put stupid jokes here?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 31st Jul 2009 07:12 Edited at: 31st Jul 2009 07:13
It's because user_input$ = "" inside the function because it's not set to global.

Add this line to the top:



If you don't want to do that you can just add the string to the function call:



cguy
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: In my Computer!
Posted: 31st Jul 2009 07:47 Edited at: 31st Jul 2009 09:53
Thanks, Grog for answering me so late. I was supicious of my problem having to do with global commands. I don't have much experience with that
I have another question. Can you use arrays while declaring functions in place of just variables? For example:


Do we all have to put stupid jokes here?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 31st Jul 2009 10:19
Np.

No, but arrays are global automatically so if you want to use an array inside the function you don't have to pass it to the function.

cguy
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: In my Computer!
Posted: 31st Jul 2009 20:03
Yeah, I was afraid of that. Thanks again.

Do we all have to put stupid jokes here?
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 31st Jul 2009 20:24
Quote: "'I was afraid of that'"


That is an odd phrasing for a feature that I see as a huge plus for DBPro. My functions can alter the huge array of enemies, or huge array of objects, or plot, dialogue etc.etc. without having to worry about passing the whole array to the function, or passing a pointer etc.

I may be in a minority here, but I prefer arrays being global!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 31st Jul 2009 20:30
Well, it would be nice to have the capability of making local arrays - and if you want a global array, all you would have to do is declare it as global:

global DIM Array(10)



Diggsey: I have a spine and memory, but one memorable guy says he hates me. What am I?
Grog Grueslayer
Valued Member
19
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 1st Aug 2009 04:22 Edited at: 1st Aug 2009 04:23
I think he means he's disappointed that we can't dimentionalize an array while defining a function.

Arrays are naturally global by default but you can localize an array using LOCAL inside the function that will produce an error if you try to access an array outside the function that made the array LOCAL. You can localize an array that is already used but it's probably a bad idea to do it (but it works).



cguy
17
Years of Service
User Offline
Joined: 3rd Nov 2007
Location: In my Computer!
Posted: 1st Aug 2009 04:59
Quote: "I think he means he's disappointed that we can't dimentionalize an array while defining a function.
"

Exactly

@ everyone
This is a bunch of useful info. Thanks so much. I'm beginning to really like functions. They are maing my life so much eaiser.

Do we all have to put stupid jokes here?

Login to post a reply

Server time is: 2024-11-25 05:01:44
Your offset time is: 2024-11-25 05:01:44