Dark Age Games
Home Dark Age EX Dark Age 2 Message Board Fan Art FAQ Kelzar Mage DALpedia MS Forum
Board Index Dark Age General Bug Report Website Off Topic Register User Edit User User List Search

Tip du Jour
Posted by: Colin
17:12:15 04-23-2004

Here's mine:

---------Data Structures
------Part 1
---Multi Deimensional Arrays

Multi-dimensional arrays are a very "mysterious" concept for those of you have have solely programmed with RPGCode. Whether you've used them or not, however, you can quickly see how they might be useful. Take a look at this (surreal) battle system's variables:

#Enemy[health]!
#Enemy[fight]!
...

What if we want more than one enemy? Many people were either so stumped that they just left their battlesystem having one enemy or adapted like this:

#Enemy1[health]!
#Enemy2[health]!
...

The only problem with that is the ease at which it can be used with for loops. Not very eaisly. I counteract this by using the all-mighty #RPGCode command.

---RPGCode(commmand$)

This command simply runs the command passed to it. CBM was originally planning on using this solely for debugginf purposes but soon enough he soon its potential usefulness and left it in.

Here is how we can use it to simulate multi-d arrays:

#Method SetMultiDLit(name$,para1!,para2!,data$)
{
#CastLit(para1!,a$)
#CastLit(para2!,b$)
#temp$="#" + name$ + "_MD_" + a$ + "_MD_" + b$ + " = data$"
#RPGCode(temp$)
}

#Method GetMultiDLit(name$,para!,para2!,dest$)
{
#CastLit(para1!,a$)
#CastLit(para2!,b$)
#temp$="#dest$ = " + name$ + "_MD_" + a$ + "_MD_" + b$
#RPGCode(temp$)
}

That is how you would do a multi-d array. These work rather nicely. Look at this example:

*Assuming the methods are avaliable for use...

*Pretend declarations...
*MDArray SomethingArray(2)(2)

*Populate the array...
#for(a2!=0;a2!<=2;a2!=a2!+1)
{
#for(b2!=0;b2!<=2;b2!=b2!+1)
{
  #Prompt("Enter something:",temp$)
  #SetMultiDLit(SomethingArray,a2!,b2!,temp$)
}
}

*Spit out the stuff...
#for(a2!=0;a2!<=2;a2!=a2!+1)
{
#for(b2!=0;b2!<=2;b2!=b2!+1)
{
  #GetMultiDLit(SomethingArray,a2!,b2!,dest$)
  #MWin("Para <a2!>,<b2!> = <dest$>")
  #system.pause()
  #MWinCls()
}
}

Thank you for reading KSNiloc's "Tip du Jour". Stay tuned for the next episode, "Stacks".

--KSNiloc
ksniloc@loggerdelta.tk

Edit Post