I have in couple of my projects made engine that is controlled by simple programming language kind of thing that uses tables for its execution. An example table could be:
Code: Select all
attackwave = {
[1] = {type=enemy, numberofenemies=2,
[1] = {x=100, y=200, type=3},
[2] = {x=300, y=200, type=1}
},
[2] = {type=displaytext, text="Incoming attack!"},
[3] = {type=enemy, numberofenemies=1,
[1] = {x=300, y=100, type=2}
}
}
Idea is that the execution would go one table index at a time. That for example in this case engine would handle that first there would come two enemies with given specifics, and after those both have been shot there would be text displayed on screen, and after displaying text have been done, the next attackwave would start.
So far this have worked somewhat okay for me, but lately my engines have become bit more complex and this is starting to show its limits.
As example I many times use program flow commands like "jump" command which i use to jump to some specific place in table (like jumping to specifil line of code) it could be for example "jump=1" which would mean that it would jump to first index of table.
Two examples about how this jump command is starting to be bit of a problem to me:
1. I can use jump=1 to jump to table[1], but what if i want to jump say, table[1][1]? Then i would need to make another command like subjump and if i want to jump to table[1][1][1], i need a third command.
2. More serious problem is that when I use program to jump to some specific place in middle of code. Say with answer 1 jump=10, ith answer 2 jump=23. So far so good, but then i decide to add more lines between lines 10 and 23, this means that i need to go back this jump=23 place, and change it accordingly.
And especially if there are more than just one jump on same piece of table code and i go on to add one line to one of the first lines, then i need to change all the jump=x lines.
So now we get to the actual question.
I have been thinking for some time now, that i need some better system for my engine codes than using tables.
I would like to rather use some written code, like hollywood does. But problem is that I dont quite get how that is done.
So how for example if I would have textfile like:
Code: Select all
Wave1:
Createenemy(1, 200, 300, 50)"
Goto Wave1:
How would I be able to read that in hollywood so I could use that info?
That how do i make hollywood understand that for example Createenemy is the command and first number inside () is enemy type, next number is x...
and how would i tell hollywood to for example find the location wave1:?
Could someone please give me some example code about this, for I dont have much clue about how this is done in practice.
All I can think about is checking everything letter by letter and comparing them to commands but that doesnt seem very practical way to do it.