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 / Anyway around this?

Author
Message
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 11th Jul 2003 11:02
Is it possible to use the contents of a variable to call a function or to DIM an array at runtime?

For instance. The player enters a string, is it possible to use that string to DIM an array. A little like this:

GLOBAL Name$ AS STRING
GLOBAL x AS INTEGER
GLOBAL y AS INTEGER
INPUT "Name of array"; Name$
INPUT "x dimension"; x
INPUT "y dimension"; y
DIM Name$(x, y)

I realise that this code itself won't work but is there any way to achieve this (perhaps with a plug-in?)
http://www.aopr79.dsl.pipex.com/tinywars/images/signature.jpg[/img]
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Jul 2003 11:05
Well, my ARRAY plug-in allows arrays to be created by name...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
Revolution
23
Years of Service
User Offline
Joined: 27th Dec 2002
Location:
Posted: 11th Jul 2003 11:43
i was thinking about this when i started to make an array editor. In the program it does not matter what the array is called, only that it is saved as in the end.

so just call your array, array1. And if you want a second array call it array2.
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 11th Jul 2003 11:47
How do you use your plug-in MrTAToad?

heartbone
23
Years of Service
User Offline
Joined: 9th Nov 2002
Location:
Posted: 11th Jul 2003 12:02
Is it possible to use the contents of a variable to call a function or to DIM an array at runtime?
Yes to both.
But if you want to Dim it again, remember to Undim the Dimmed array first.

The more you see, the more you know.
The more you know, the more you see.
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Jul 2003 12:43
There's an example routine on my web site - along with the plug-in.
The reason for the plug-in is because I dont think you can create run-time defined arrays...

name$="AnArray"
dim name$(100) - As far as I know, this wont work (ie wont create an array of AnArray(100)).

The only slight problem with my plug-in is that string are fixed width, but as long as your not defining 1Gb string sizes, and then only using it to store the word "hello", it shouldn't be any cause for concern.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 11th Jul 2003 16:04
MrTAToad,

I downloaded the array plugin and popped it in the compiler/plugins-user directory. I ran the testarray program but it says:

'variable getStringFromIndex' does not exist in program'

and won't compile. What have I done wrong?

P.S. I also have the memory plugin that your site said was required.

PPS. This plugin will allow me to create an array using the contents of a variable at runtime won't it?

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Jul 2003 16:28 Edited at: 11th Jul 2003 16:34
Yes, you'll be able to create arrays using a variable (as long as its a string name). I'll have a look at that problem later - probably forgot to put in the new resource name, when I changed it...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 11th Jul 2003 16:29
Thanks

FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 11th Jul 2003 16:30
What is the syntax for the plugin?

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Jul 2003 16:37 Edited at: 11th Jul 2003 16:43
What do you mean ? If your refering to the getString command - its the same syntax (I just forgot to update the values passed in the string list). I'll update it when I get home from work... Even a genius such as moi, do sometimes make mistakes...

For the time being you can REM out the offending line...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 11th Jul 2003 16:42
I think I should probably explain what i'm trying to do here as there may be an easier solution anyways.

In my hacking simulator, it will be possible to write your own functioning programs to use in the game. The 'programming language' in the game is unique and contains only a few commands.

What I am trying to do is that when the player wants to write a program in the game, they select a filename for this program. I then want to DIM and array that has the same name as this filename. For instance, if they wanna call their program 'UltraVirus', it will DIM an array like so:

DIM UltraVirus(100)

I will then save each line of code that the player writes to an element in this array. My parser (that I am writing) will then look through this array and work out what the program should do. Does this make sense? As you can imagine....it is imperative that the array my parser scans through is the one that contains the correct 'code'. Also, the array needs to be preserved for use later in the game.

Is this a pants way to go about things and how can I use the plugin to achieve this?

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Jul 2003 16:43 Edited at: 11th Jul 2003 16:53
My plug-in should be able to handle it, unless you want multi-dimensional arrays (which is possible but harder as you need one array to index the other). I haven't put in anything for generic (ie TYPEd data yet, but with IanM's array accessing module, it should be easy enough).

What you would do is get the users filename/array name, and create it, like so :



which would allocate 4K of 256 byte strings...

Then for each further input, you would put into the array at a given position, using something like :



(Or the more fancy way would be :
)

If you want to search, you would need to go through the complete array size (if your deleting objects) or the number of elements...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 11th Jul 2003 16:52
OK, I think I get that.

How would I reference the created array at a later time? For instance, taking the example of an array that has now been created called 'UltraVirus'?
If I wanted to find out what was at position(x) how would I code it?
I can't imagine this would work:

INPUT "Name of array ", name$
INPUT "Position ", position
PRINT name$(position)

This would fail as there is no such array called name$ in the program.

MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Jul 2003 16:55 Edited at: 11th Jul 2003 17:01
The way to read in the data would be :



Whilst this command is temporary unavailiable, it wont be shortly.

The x-1 is there, because in the demo, I use values from 1 upwards, whereas internally they are stored from 0.

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!
MrTAToad
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 11th Jul 2003 21:26
I've uploaded a new demo - the problem was a $ missing at the end of the offending command...

Good news everyone! I really am THAT good...
http://www.nickk.nildram.co.uk/ for great plug-ins and other exciting things - oh my, yes!

Login to post a reply

Server time is: 2026-07-18 07:31:03
Your offset time is: 2026-07-18 07:31:03