RPGDXThe center of Indie-RPG gaming
Not logged in. [log in] [register]
 
 
Post new topic Reply to topic  
View previous topic - View next topic  
Author Message
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Sun Nov 30, 2003 2:18 pm    Post subject: Looping structure in scripting language [quote]

I just made a simple looping structure in my scripting language. The way it works is, while it's interpreting the text word by word, if it finds the word LOOP then it gets a pointer to the position in the file using tellg(). And when it finds the word LOOPBACK it simply uses seekg to zip back to the beginning of the loop. But something weird happens. When I loopback, it loops to a position a certain number of spaces after the LOOP statement. And that number of erroneous spaces is different depending on the position of the LOOP. Now this is weird because I expect tellg to tell me where I am in the file, not to say "uh... you're kinda somewhere in the 43857 area, give or take a bit." What could the problem be?

UPDATE:

After googling a bit, it seems I'm not the only person to run into crazy problems with tellg. The problem could be that MingW screwed up the implementation of tellg in non-binary modes... though that sounds like a pretty major, glaring error that would have been noticed and fixed...

SECOND UPDATE:

Yep, changing it to binary input fixed everything. I rule!
A new record: I think I figured this out before anyone even READ my post :)
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
valderman
Mage


Joined: 29 Aug 2002
Posts: 334
Location: Gothenburg, Sweden

PostPosted: Sun Nov 30, 2003 5:51 pm    Post subject: [quote]

I think reading text scripts from disk and interpreting them at the same time is a really bad idea...sounds slow. Of course, this only matters if you constantly have scripts running, like one weather script and a crapload of AI scripts.
_________________
http://www.weeaboo.se
Back to top  
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Sun Nov 30, 2003 11:17 pm    Post subject: [quote]

Nah, the scripts are only read when you hit an entity, like when you're talking to someone or when you exit a map. If I had constantly running scripts I'd put 'em in memory on map load, but for my purposes that's a bit of overkill.
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
Bjorn
Demon Hunter


Joined: 29 May 2002
Posts: 1425
Location: Germany

PostPosted: Mon Dec 01, 2003 1:41 am    Post subject: [quote]

What if you want to store your scripts in datafile later? Ah ok, then you can think about that later as well. :-)
Back to top  
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Tue Dec 02, 2003 1:01 am    Post subject: [quote]

hmm... interesting. I suppose if I go into datafiles, putting scripts into memory would be an option.

Hey, while I'm here, I might as well show off a snippet of what my scripting code looks like:

Code:

object TARA {
 text { Tara: Let's Dance! }
 text { Bokk: Sure, why not? }
 int myloop 1
 loop
  move 3 right 0 left stop
  move 3 left 0 right stop
  inc myloop 1
  if myloop 7 [
   erase myloop
   break
  ]
 loopback
}


entity #3 is tara and entity #0 is the player. I will very soon add the ability to reference entities by name.
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
valderman
Mage


Joined: 29 Aug 2002
Posts: 334
Location: Gothenburg, Sweden

PostPosted: Tue Dec 02, 2003 1:56 am    Post subject: [quote]

That looks almost as cryptic as the ASM code for my VM... ;P
_________________
http://www.weeaboo.se
Back to top  
XMark
Guitar playin' black mage


Joined: 30 May 2002
Posts: 870
Location: New Westminster, BC, Canada

PostPosted: Thu Dec 25, 2003 11:18 pm    Post subject: [quote]

Yay! I just simplified the scripting engine so it has an internal value for the loop counter so you don't have to do loops manually.

Code:

object TARA {
 text { Tara: Let's Dance! }
 text { Bokk: Sure, why not? }
 loop
  move TARA right PLAYER left stop
  move TARA left PLAYER right stop
 loopback 7
}


now that's a little simpler :)

note: I can also put a variable after loopback instead of a constant number
_________________
Mark Hall
Abstract Productions
I PLAYS THE MUSIC THAT MAKES THE PEOPLES FALL DOWN!
Back to top  
Post new topic Reply to topic Page 1 of 1 All times are GMT
 



Display posts from previous:   
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum