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 / variables as parameters

Author
Message
BasketBallBen
23
Years of Service
User Offline
Joined: 24th Mar 2003
Location:
Posted: 1st Dec 2003 00:45
i'm havin more problems tryin to get used to this language after others...but how come i can't use variables(or more importantly, arrays, but let's get these working) in the parameters and modify them so they change globally.

sync rate 60
sync on

global test

do
set cursor 0,0
print test
add_test(test)
sync
loop

function add_test(what)
inc what
endfunction

why doesn't test inc each frame? it's a global variable so it changes if i change it directly in the function, but not as a parameter.

then i would need a way to pass arrays as parameters
ex-

sync rate 60
sync on

dim test(2)
test(2) = 100

do
set cursor 0,0
print test
add_test(test)
sync
loop

function add_test(what)
what(1) = what(1)+1
what(2) = what(2)+1
endfunction

like that. maybe theres a secret im missing that signifies to the engine that im using an array instead of a variable. but since my first example didn't work like i planned, im wondering whats going on.
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 01:56
inc what

should be inc what,#

where # is the increment amount!

-----

~ J ~
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 01:58
WITHOUT sounding sarcastic, if I gave you 10p and asked you to increment it, would you be in your rights to ask how much by?

If so, then surely your DBPro program has the same rights...!

HTH

-----

~ J ~
BasketBallBen
23
Years of Service
User Offline
Joined: 24th Mar 2003
Location:
Posted: 1st Dec 2003 02:03
still not understanding why it doesn't work, but i've found a way around it..the first problem.
but i still need to find a way to pass arrays as parameters.

ex-
sync rate 60
sync on

dim my_array(3)

do
set cursor 0,0
print my_array(1)
print my_array(2)
print my_array(3)
add_array(my_array)
sync
loop

function add_array(test)
inc test(1)
inc test(2),2
inc test(3),3
endfunction

is it possible to get the results i want?
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2003 02:04 Edited at: 1st Dec 2003 02:06
Nope, the command is quite valid, and increments by 1.

The problem is that he doesn't yet have an understanding of what labelling a variable 'global' does in DBPro.

All DBPro parameters are passed by value, so changing them only changes the temporary copy - even if the variable that you are passing is global.

If you want to increment a global, then you should just increment it using its global name


Your first piece of code




Arrays defined outside of a function are automaticall global, and you can't pass an array to a function ...

Your second piece of code




[EDIT]Oops, too late. You can 'sort of' pass an array by reference, but you would need to use my array plug-in ... plus it's a bit temperamental and easy to crash[/EDIT]
BasketBallBen
23
Years of Service
User Offline
Joined: 24th Mar 2003
Location:
Posted: 1st Dec 2003 02:06
actually, if you don't give the inc amount, it adds 1 by default. thats not my problem though, i could just as easily change the code to "what = what+1" or "inc what,5" and it wouldn't work. the problem isn't in the inc...it's in the syntax, either dbpro can't do exactly what i want(but there should be ways around it) or i'm not using the right syntax.
JSN
22
Years of Service
User Offline
Joined: 8th Nov 2003
Location: 127.0.0.1
Posted: 1st Dec 2003 02:10
(tap tap) (tinker tinker) (hmmm hmmm) (blush blush)

My apologies, I didn't realise it did increment by one...

-----

~ J ~
BasketBallBen
23
Years of Service
User Offline
Joined: 24th Mar 2003
Location:
Posted: 1st Dec 2003 02:13
IanM -
Most importantly...you can't pass arrays to functions? that's a shame and is going to make things a lot more difficult. do u think it will ever be implemented?
secondly...i guess the parameters only get passed as value thing clears up the problem, and that sux too. i don't know what i'm going to do with myself anymore, lol.
now i'm kinda frustrated, that throws out a lot of my programming style that worked in another program, but i think i have a way around it, just a pain in the ass.
but even if you did make me a little more depressed, i'm not gonna kill the messenger so thanks for the help
CattleRustler
Retired Moderator
22
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 1st Dec 2003 02:59 Edited at: 1st Dec 2003 03:10
sw

-RUST-
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 1st Dec 2003 14:41
Quote: "Most importantly...you can't pass arrays to functions? that's a shame and is going to make things a lot more difficult. do u think it will ever be implemented?"


Nope, you can't natively pass arrays. But we live in hope. Although I have my doubts, as I've hounded lee about this feature for years.. In the mean time, IanM came up with a plug in work around for now though.

Kevin Picone
Play Basic - Visible Worlds - Kyruss II
[url]www.underwaredesign.com[/url]
BasketBallBen
23
Years of Service
User Offline
Joined: 24th Mar 2003
Location:
Posted: 1st Dec 2003 21:30
whats the plug in do and where can i get the it?
Jaze
22
Years of Service
User Offline
Joined: 20th Nov 2003
Location: Connecticut, USA
Posted: 1st Dec 2003 21:34
By Value By Default? Usually its by reference - and then it sounds like we don't really have the option to by reference? IF this is true - thats a real CAVEAT boy

-=/Jaze/=-
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2003 22:11
Example code can be found here (my second post) http://developer.thegamecreators.com/?m=forum_view&t=16041&b=5

You can get the plug-in from my site
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 2nd Dec 2003 04:54
Jaze:

Dbpro, only supports by value.

Kevin Picone
Play Basic - Visible Worlds - Kyruss II
[url]www.underwaredesign.com[/url]
ZomBfied
23
Years of Service
User Offline
Joined: 2nd Oct 2002
Location:
Posted: 2nd Dec 2003 22:30
No byref.... You could do cool things with a little byref.
Jaze
22
Years of Service
User Offline
Joined: 20th Nov 2003
Location: Connecticut, USA
Posted: 5th Dec 2003 10:11
YEah - I see I'm not the only one who ran into a wall, got a concussion, stepped back and had to totally rethink and redesign their programming approach to get things going...but I am finding that once you choke on the multi word(y) syntax, the strange by value rule, the array prob, the fact that Dim statements are more like GETMEM function calls....You can make some really neat stuff pretty quickly.

-=/Jaze/=-

Login to post a reply

Server time is: 2026-07-26 20:14:33
Your offset time is: 2026-07-26 20:14:33