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.

Geek Culture / Need example of scripting

Author
Message
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Sep 2008 09:22 Edited at: 24th Sep 2008 09:26
<Meant for this post to under the Dark Basic Pro board.>

QUESTION/Request
So I would be truly appreciative if anyone could give me the equivalent of a "Hello World" example of scripting with DBPro. I don't necessarily need it to be in any particular scripting language, and a simple custom script/parse will also due.

~~~~
Why am I asking?
Here's a bit of irony. I understand the reasons for scripting, and the idea behind it; separating game logic from the core engine, making modifiable scenarios, being able to see things in action on the fly, not having to recompile the entire program to make a game logic change, etc...

SO I know it's something I would like to incorporate into my development. BUT....

I just don't understand how to put it into practice. Everything I google just gets to involved in the specifics of a scripting language, or too heavily involved with another language that I just don't seem to get it. Also, I'm not sure how or why scripting is different then me reading data from files into my game (except for the fact that I can't really type "Spawn ("gnome",param,param,param...)" and see it happen.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 24th Sep 2008 09:26
Zotoaster has made several examples of scripting, you should check those out first - I think one of them is being featured in this months newsletter, but code snippets should be the place to look.


Health, Ammo, and bacon and eggs!
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 24th Sep 2008 09:27
thx Van B, I'll check it out now.

NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 24th Sep 2008 11:08
The way the darkSMASH script parser worked was to first remove spaces, then scan the whole file into a two dimensional array with commands and then up to eight parameters using ( and , and ) to split up commands. It was dead quick.

The best way in which to divide a script up like this is to read it in one byte at a time, storing the bytes until the character the program is looking for is found.

The darkSMASH script system was pretty simplistic although it did have if/endif blocks. Start small. Begin by just making your parser split a list of commands into strings in an array, and then have an interpreter fly through that array.

Roxas
19
Years of Service
User Offline
Joined: 11th Nov 2005
Location: http://forum.thegamecreators.com
Posted: 24th Sep 2008 17:35
Nex thats really how i did it on my Flare Engine tho later i made compiler for scripts too that compiled script to machine code and was lighting fast lol. I dont remember the site but there was good site to learn scripting and make compiler for scripts etc. Someone posted it to these forums.

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Sep 2008 19:51
That's the most efficient way really to make any scripting system. Once you understand all the steps required, it's rather simple. You start with the lexer/tokenizer, which as Nex said, should split the script into little "words". The compiler should read those words and make a list of simple instructions, with 0 or a few parameters. I recommend for extra speed you don't store the instructions or parameters as strings though (unless the parameter itself is supposed to be a string), but more like a value representing an instruction. i.e., the instruction "push" might have a value 1, and "print" have a value of 2. You might have an instruction list such as:


... which would of course print "hello world" to the screen.

All it takes then is to interpret the bytecodes one by one to execute the script.


I'm considering writing a tutorial on this, heheh

NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 24th Sep 2008 19:59
The arena scripts for darkSMASH did do that in fact, because code was being interpreted every frame. The commands were converted to a list of bytecode, each of which had a pointer pointing at a memblock with parameters...

Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 24th Sep 2008 20:08 Edited at: 24th Sep 2008 20:11
Quote: " each of which had a pointer pointing at a memblock with parameters"


That's rather clever I think. It depends what you want to do as far as compiling though. Sometimes you might want somewhat game-specific scriping systems, in which case you could use a SIMD (single instruction multiple data) instruction list, as you did. I tend to try and make mine rather flexible, so mine don't require many parameters (never found myself using more than two), so for that reason I just have a UDT to store instructions with their parameters, such as:


Login to post a reply

Server time is: 2024-11-20 16:19:13
Your offset time is: 2024-11-20 16:19:13