Author Topic: Would a "higher level" AGI compiler be useful?  (Read 29345 times)

0 Members and 1 Guest are viewing this topic.

eidolon

  • Guest
Re: Would a "higher level" AGI compiler be useful?
« Reply #45 on: March 22, 2002, 02:03:40 AM »
How would the compiler choose logic number for rooms?
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #46 on: March 22, 2002, 02:07:29 AM »
I thought first come first served would be best.  You'd have to make sure logic.0 was logic 0 but the rest it wouldn't matter as much.

logics that represent rooms could have a picture associated with it, so the picture has the same number as the logic.

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

eidolon

  • Guest
Re: Would a "higher level" AGI compiler be useful?
« Reply #47 on: March 22, 2002, 02:19:37 AM »
In the proposed syntax, how would OnNewRoom{} etc work?

Would they simply replace the equivalent if statement?

Would they be more like function definitions? If so, in what order would they be called?
Could this potential arbitrariness cause problems or bugs?

« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #48 on: March 22, 2002, 02:30:23 AM »
That's a good point and I've been thinking about it..

we could
1) call it like functions from the main code
2) compiler does it automatically (ie, replace the equiv if statements)

I like 2 because it makes the room definition less kludgey but with 1 you could say when anything is called.  In the definition of the syntax, it could be said that OnNewRoom is checked first.. with OnTouchLeft, TimerUpdate, all that left for last..

it's just an idea.. if everybody feels it would be better just to have it as functions as not part of the room defintion.. that would be cool.

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #49 on: March 22, 2002, 08:45:50 AM »
I'd lean more toward compiling them to normal if statements, as well.

In compiling functions, you'd have to look out for mutual recursion as well as regular recursion. With inlining, functions calling functions will technically work (as long as you watch out for mutual recursion), but it could very easily produce some massively bloated code. Although I understand the aim is to produce a high-level syntax, I think efficient implementation is an absolute requirement. If it's not efficiently implementable, then maybe it shouldn't be included at all.
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #50 on: March 22, 2002, 08:53:58 AM »
By the way, I know that the syntax listed in the discussion isn't supposed to be final, but unless there's some reason to have those parentheses after the OnNewRoom, etc., then I think it would be better to just leave them off.

You could, I guess, also have a way to define new event handlers; for example:

room r
{
 event OnTimerExpire (vCounter == 50);

 OnTimerExpire
 {
 }

}

which could then compile to a simple

if (vCounter == 50)
{
}
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #51 on: March 22, 2002, 01:40:18 PM »
I thought the brackets would help consistancy.

here's how I thought a timer could work..  some people don't use a timer just for one thing..

room r
{
/* what about a multipler?.. do we want it to follow the number of game loops or every second loop? */
 Timer t;
/* should we define the variable used for t or not? */

 Main
 {
   if (said("hello"))
   {
   // inline "function'
   t.init(0);  // 0 in case you want to start later for debugging
   }

   // this is a problem though.
   print("timer=%v(t)")
 }

 // when timer reaches ten
 OnTimer(10)
 {
 }

 // for large numbers, the timer could use two vars, it would just update two on the game loop.
 OnTimer(1024)
 {
 }

}

One thing I would also like is the ability to have a one line if statement without using scope brackets.

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #52 on: March 22, 2002, 03:15:16 PM »
If the parentheses will be used for some of the event handlers than it would be better for all of them to have them. I just hadn't seen any that used them.

I wasn't really talking about timers specifically. I was really talking about something more general, such as

room r
{
 event OnPlayerStandingInTheRightSpot(posn(ego,1,2,3,4));

 OnPlayerStandingInTheRightSpot
 {
 }

}

basically:

event event-name (condition that triggers the event);

I don't necessarily mean that as a syntax suggestion. I'm just suggesting the possibility of user-defined events.
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #53 on: March 22, 2002, 03:17:55 PM »
What do you mean by a one-line if statement? Do you mean

if (f3)
 v1 = 2;

kind of thing? I would like to see that, but only because I want to be able to say

if (f3)
{
}
else if (f4)
{
}
else if (f5)
{
}
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #54 on: March 22, 2002, 03:49:48 PM »
yes, sorry.. that's what I meant.

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #55 on: March 22, 2002, 04:04:20 PM »
how would we define the order that the events are checked however?  you might want to define a said("eat", "ham') event before a said("anyword"). or one OnObjInBox before another if they overlap..

should it just fall on the order they are defined?  but make sure that the OnNewRoom event is checked before any other.

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #56 on: March 23, 2002, 07:34:41 AM »
I wouldn't say that it would be necessarily be a good idea to completely substitute events for if statements even though in many cases they could more or less be considered the same thing. There are cases such as:

if (said("look", "tree"))
{
 if (vDayNumber == 1)
 {
   print("The tree is nice.");
 }

}
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #57 on: March 23, 2002, 07:43:26 AM »
Ok, I gotta stop writing code in these boxes. I keep forgetting that the tab key moves you to the Post button.

I wouldn't say that it would be necessarily be a good idea to completely substitute events for if statements even though in many cases they could more or less be considered the same thing. There are cases such as:

if (said("look", "tree"))
{
 if (vDayNumber == 1)
 {
   print("The tree is nice.");
 }
 else
 {
   print("The tree was cut down yesterday.");
 }
}

That example was really meant to illustrate an if statement inside something that could be considered an event, but I also just realized that any time you want to have an else branch might be problematic with that event syntax.

OnNewRoom
{
}
else
{
}

seems pretty awkward to me. Otherwise, I'm thinking that the entire room should be executed the same way that logics are executed currently, with a Main section not being required, so something like the following could be said:

var vSomeVar = 0;

room r
{
 

 OnNewRoom()
 {
 }

 vSomeVar++;

 // I know this isn't necessary for this example,
 // but there might be some situation where
 // it is cleaner

 OnNewRoom()
 {
   print("You've visited this room %vSomeVar times.");
 }

 // the following section optional
 Main
 {
 }
}
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Joel

Re: Would a "higher level" AGI compiler be useful?
« Reply #58 on: March 23, 2002, 07:48:11 AM »
Well, actually, that code in my last example was bad, anyway. It wouldn't give the correct answer, but the point was that there might be something that you want to execute before an event handler is invoked that might be awkward to put inside Main and there might (possibly) be a case where you want an event handler executed twice in the same interpreter cycle.

I think, ultimately, statements such as if (fNewRoom) should still be legal. That would make the new syntax fairly flexible. User defined events may not be easy to work with, so it may be better not to have them. I was just thinking consistency.
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »

Offline Nick Sonneveld

Re: Would a "higher level" AGI compiler be useful?
« Reply #59 on: March 23, 2002, 03:37:52 PM »
The problem is that people code event's in other languages assuming that they don't know when it's going to occur.  In AGI we actually can define when they check for events..

I thought it was a nice idea..  perhaps we should just do what you suggest.. remove the Main() distinction (although I'd like to keep it if we decide to add something else) then use macro's for

OnNewRoom()

to

if (isset(newroom))

- Nick
« Last Edit: December 31, 1969, 07:00:00 PM by 1018072800 »
Nick Sonneveld  |  AGI Dev  |  NAGI


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.022 seconds with 16 queries.