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 / passing arrays to a function

Author
Message
Fluffy Paul
22
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 6th Mar 2003 00:34
Is there any way you can give a function to an array?

I have these arrays that all have the attribute .symbol and at some point I need to search the arrays to find an element who's .symbol matches a given string.
At the minute I need one function for each array but all the functions are identical. Being a champion of efficient code this sickens me.

Check it out:



what I really want to do is just have one function that does the checking but I tell it what array to check. So instead of checking things(0) by calling check_things() I want to have a check_array() that looks like this:



and I would say check_array( things(0), "text" )

When I tried it it didn't like it. I want to know if such a thing is possible before I keep plugging away. Remember: I KNOW arrays are global already. I just want less repetition in my code.

Thanks!
Ending a sentence with a French word is so passé
MrTAToad
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 6th Mar 2003 00:46
No, you cant pass arrays into functions.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins - oh my, yes!
Fluffy Paul
22
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 6th Mar 2003 00:51
Ah crap!
I had a feeling...

Ending a sentence with a French word is so passé
Andy Igoe
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 6th Mar 2003 01:17
Slightly slower but a lot neater...



Pneumatic Dryll, Outrageous epic cleric of EQ/Xev
God made the world in 7 days, but we're still waiting for the patch.
Andy Igoe
22
Years of Service
User Offline
Joined: 6th Oct 2002
Location: United Kingdom
Posted: 6th Mar 2003 01:18
Or even...



Pneumatic Dryll, Outrageous epic cleric of EQ/Xev
God made the world in 7 days, but we're still waiting for the patch.
Fluffy Paul
22
Years of Service
User Offline
Joined: 16th Dec 2002
Location: United Kingdom
Posted: 6th Mar 2003 01:47
That is neater.
The arrays belonged to different sections in my program -
there's a section for handling models and allocating object numbers, there's a section that handles "entities" (the actual data of things in the game like health, name and so on, one piece of which is the object number) but all these are initialised from a file. So I have to store the symbol (or the name) the person used in the .ini file so if they say:

tank1.health=5
tank2.health=10
tank1.armour=5
tank2.armour=6

my program knows how to check the symbols used to describe tanks so it can work out if a line in the .ini file is talking about a tank that it's seen info about before, or if it's a new tank entirely.
at the minute each section knows how to search the array that it contains - I just wanted to write a single function that could search any array you give it - coz that's neater and more reusable. It's cool as it is.
It's my final year project for University and it's very cool. I'll release the source when it's finished.

Ending a sentence with a French word is so passé

Login to post a reply

Server time is: 2025-05-19 04:08:25
Your offset time is: 2025-05-19 04:08:25