GameMonkey Script

GameMonkey Script Forums
It is currently Sun Jan 20, 2019 11:06 pm

All times are UTC




Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sun Apr 26, 2009 4:47 pm 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
I just released this code into a clean version of 1.25l and it worked fine - have you upgraded from 1.25j to 1.25l (which includes FORK).


Top
 Profile  
Reply with quote  
PostPosted: Fri May 01, 2009 6:01 am 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
btw if you are feeling brave, i'd love to see lua style multiple return value support in GM

Code:
x,y,z = getposition();


basically function calls can push an arbitrary number of values, and i believe the count of how many it pushes, and it ends up plopping them in order to the comma delimited variable list. I think it even allows you to do partials, ie

Code:
x,y = getposition()


this would be useful to avoid creating tables all the time to pass stuff, which results in creeping up memory and eventually hits the GC.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 01, 2009 7:23 am 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
I think you'd have to support partials to keep the majority of GM working the way you're used to.

How does it handle scoping? Do they all have to be in the same scope?

Code:
global x,y,z = getvector();


Or can they be put into different scopes per variable?

Code:
global x, local y, member z = getvector();


I imagine it's the former.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 01, 2009 3:55 pm 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
what do you mean partials? I'm not sure how it handles scoping.

iirc, in lua not only do you push the return values onto the stack but you also return the number of arguments pushed, which is I'm guessing a component of the multiple return values. In GM, presumably we would use that in place of return GM_OK, which is kinda nice, because the enumeration that GM_OK belongs to only defines negative values for error codes or system messages. even better would be that the gmThread would track that itself by counting the pushes. I never liked how low level lua was kept. Manually pushing and popping stack shit is rather annoying.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 01, 2009 5:43 pm 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
In GM it's actually pretty easy to see how many values were pushed. GM actually does a comparison itself to work out if it needs to push a null or not - GM functions always return a value, even if you don't specify one... it defaults to pushing a NULL. When a script call is made, GM keeps track of the top of stack offset - when you push a value the top obviously changes.

I had half an hour on this today and think I have a way of doing it. I looked at Lua's syntax and some of it is a bit obscure - if we want to implement this functionality we need to be specific as to the usage of it. For example, does it need to be exactly as Lua does it, or would something more GM-like be applicable?

Eg:

Code:
getVector() = function() { return 10,20,30; };
x,y = getVector();  // x = 10, y = 20, 30 is discarded
x,y,z,w = getVector(); // x = 10, y = 20, z = 30, w = null


Lua seems to allow stuff like:

Code:
getVectorW() = function() { return getVector(), 40; };
x,y,z,w = getVectorW(); // x = 10, y = 20, z = 30, w= 40


What happens if the lhs values are members of stuff?

Code:
v = { x = 0, y = 0, z = 0 };
v.x, v.y, v.z = getVector();  // populates the members of v.x, v.y and v.z with 10, 20, 30


Top
 Profile  
Reply with quote  
PostPosted: Fri May 01, 2009 6:00 pm 
Offline

Joined: Fri Jan 14, 2005 2:28 am
Posts: 439
downgraded wrote:
Code:
getVector() = function() { return 10,20,30; };
x,y = getVector();  // x = 10, y = 20, 30 is discarded
x,y,z,w = getVector(); // x = 10, y = 20, z = 30, w = null



Yea that looks great.

Quote:
Lua seems to allow stuff like:

Code:
getVectorW() = function() { return getVector(), 40; };
x,y,z,w = getVectorW(); // x = 10, y = 20, z = 30, w= 40



Hmm, I don't know what the added complexity of something like this is, but it's not something I would personally use I don't think.

Quote:
What happens if the lhs values are members of stuff?

Code:
v = { x = 0, y = 0, z = 0 };
v.x, v.y, v.z = getVector();  // populates the members of v.x, v.y and v.z with 10, 20, 30


I would hope this would work as expected. It should be assignable to anything I would think.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 01, 2009 6:08 pm 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
Hmmm, all of this talking about it is making me consider trying it, just to see if I can do it...!


Top
 Profile  
Reply with quote  
PostPosted: Wed Nov 02, 2011 2:37 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
Hey, i think something is wrong with the error reporting in switch statements. It seems to point to the wrong line number. Here's my code:

Code:
                        switch(words[0])
                        {
                           case "NAME": {
                              if(tableCount(words) >= 2)
                              {
                                 name = words[1];
                              }
                           }
                           
                           case "IMAGE": {
                              if(tableCount(words) >= 2)
                              {
                                 npc.image = words[1];
                              }
                           }
                           
                           case "SERVERCODE": {
                              line = fHandle.ReadLine();
                              while(line != "SERVERCODEEND" && !fHandle.Eof())
                              {
                                 servercode += line + "\n";
                                 line = fHandle.ReadLine();
                              }
                           }
                           
                           case "CLIENTCODE": {
                              line = fHandle.ReadLine();
                              
                              while(line != "CLIENTCODEEND" && !fHandle.Eof())
                              {
                                 clientcode += line + "\n";
                                 
                                 line = fHandle.ReadLine();
                              }
                           }
                        }

Now the error in my code is actually here:

Code:
                           case "IMAGE": {
                              if(tableCount(words) >= 2)
                              {
                                 npc.image = words[1]; //THIS IS MY ERROR
                              }
                           }


But it reports it here:
Code:
                           case "CLIENTCODE": {
                              line = fHandle.ReadLine();
                              
                              while(line != "CLIENTCODEEND" && !fHandle.Eof())
                              {
                                 clientcode += line + "\n";
                                 
                                 line = fHandle.ReadLine(); //This is the line that is being reported as error
                              }
                           }


Error from the log:
Code:
[11/02/11 14:54:24][class Server] [GameMonkey]setdot failed.
[11/02/11 14:54:24][class Server] [GameMonkey]
unknown(580) :
                line = fHandle.ReadLine();


Was very confused at first because there is no setdot in the reported line.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 23 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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 post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group