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 Discussion / GoTo and GoSub

Author
Message
Krast0r
20
Years of Service
User Offline
Joined: 25th Jun 2004
Location: UK
Posted: 25th Jun 2004 23:01
I'm currently working with a team of people on an RPG, and it's all been going well until i started creating the functions for finding the stats of different in-game races (elves etc.). I tried using a gosub command in an IF statement inside a function, and it wont work. I tried using GoSub and still it didnt work. It says that the label cannot be found, so i tried using a different label for the GoTo function, and every did Copy+Paste to make sure it was exactly the same in both the label and in the command. I also tried using an existing (working) label and it still didn't work. Does anyone have any ideas? I use DarkBasic Classic.

In theory, theory and practice are the same, but in practice they are not.
[email protected] - That's Right! I'm a Gmail Beta Tester!
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 25th Jun 2004 23:20
Can i see your code? Make sure you have a : after the label so,

If go_stats = 1
gosub stats
endif

stats:
health = 100
armor = 50
return

"Could you do something where you don't need a video card cause i don't have one" - Program Expert
Krast0r
20
Years of Service
User Offline
Joined: 25th Jun 2004
Location: UK
Posted: 26th Jun 2004 00:07
Yeah i checked for syntax and spelling mistakes hundreds of times, takes ages becuase I have very messy code ! I could send you some of the code but because we have an investor I would need you to agree to a standard Non-Disclosure Agreement (basically just so you cant steal our source lol, you wouldn't really want to anyway it's very poorly written!)

In theory, theory and practice are the same, but in practice they are not.
[email protected] - That's Right! I'm a Gmail Beta Tester!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Jun 2004 00:09
Quote: "I tried using a gosub command in an IF statement inside a function, and it wont work."


Gosub in functions can only jump to labels declared *inside* a function (local scope).
So while this is possible:


this is not possible:


Play Nice! Play Basic!
Krast0r
20
Years of Service
User Offline
Joined: 25th Jun 2004
Location: UK
Posted: 26th Jun 2004 00:17
I think the problem is that I have several nested functions. I have 5 different functions with the EndFunction statements inside an IF statement at the end of anotehr section, like this:



Or something like that. The actual code is even more confusing and badly written!

In theory, theory and practice are the same, but in practice they are not.
[email protected] - That's Right! I'm a Gmail Beta Tester!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Jun 2004 01:27
Nested functions don't work in DB. Also if you want to exit a function within an IF statement, use Exitfunction instead of Endfunction.

Play Nice! Play Basic!
Krast0r
20
Years of Service
User Offline
Joined: 25th Jun 2004
Location: UK
Posted: 26th Jun 2004 13:23
Damn, time to rewrite! Any suggestions for making it so i dont have to write out all the stats for every function?

In theory, theory and practice are the same, but in practice they are not.
[email protected] - That's Right! I'm a Gmail Beta Tester!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Jun 2004 15:23
Quote: "Any suggestions for making it so i dont have to write out all the stats for every function?"

I think arrays can be useful here. Ie.
You have 3 characters: Matt, Tom, and Joe; and the stats: Health, Agility and Mana.


Or you use one 2 dimensional stat array (provided all stats take the same data type; in this case Integers)


If you use character IDs instead of names you can drop the Select/Case block



Play Nice! Play Basic!
Krast0r
20
Years of Service
User Offline
Joined: 25th Jun 2004
Location: UK
Posted: 26th Jun 2004 21:05
Thanks, I was thinking about using arrays before but let's just say they've never been my best friend !

In theory, theory and practice are the same, but in practice they are not.
[email protected] - That's Right! I'm a Gmail Beta Tester!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 26th Jun 2004 22:02 Edited at: 26th Jun 2004 22:02
Quote: " Thanks, I was thinking about using arrays before but let's just say they've never been my best friend ! "


If you have questions about them, just shout it out.

Play Nice! Play Basic!
Krast0r
20
Years of Service
User Offline
Joined: 25th Jun 2004
Location: UK
Posted: 27th Jun 2004 16:32
I'm having trouble already! I can't seem to be able to set the stats (for example Health) to any value, and when I do:
character$ = "Matt"
PRINT GetStat(character$, 2)
it just returns returns 0.

In theory, theory and practice are the same, but in practice they are not.
[email protected] - That's Right! I'm a Gmail Beta Tester!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 28th Jun 2004 00:41 Edited at: 30th Jun 2004 08:22
...

Play Nice! Play Basic!
empty
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: 3 boats down from the candy
Posted: 30th Jun 2004 08:22
Works perfectly here.




Play Nice! Play Basic!

Login to post a reply

Server time is: 2025-05-25 01:08:00
Your offset time is: 2025-05-25 01:08:00