Closed Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: [E2] gvar overhaul

  1. #1
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Wink [E2] gvar overhaul

    What's New
    I've remade gvars from scratch. They are now much more optimized. I kept most of the old function names for compatibility.
    The old syntax works just like usual, except the fact that gSetGroup now persists (it didn't before). However, it is recommended to use the new syntax for several reasons:
    1) The old syntax still only supports the same data types as it did before (strings, numbers, vectors, angles and entities), while the new syntax supports EVERY SINGLE type.
    2) The new syntax's syntax is a lot neater and easier to use.
    I was not able to find any bugs, but please report any bugs as soon as possible so that they can be fixed.



    Tutorial
    I'll now take some time to go through exactly how the new syntax works.

    Functions
    A list of all functions now available:
    Code:
    Function		Returns		Description
    - New syntax -
    gTable(S)		GT		Returns a non-shared gtable with the group 'S'
    gTable(S,N) 		GT		Returns a gtable with the group 'S'. 'N' determines wether or not it is shared.
    GT:remove*(S)		*		Removes and returns the variable of the type '*' at the index 'S'
    gRemoveAll*()		-		Removes all variables of the type '*' in your non-shared table.
    gRemoveAll() 		- 		Resets the entire non-shared table (ie ALL your variables in every group)
    
    - Old syntax -
    gSetGroup(S)		-		Sets the E2's current group. Does persist.
    gGetGroup()		S		Gets the E2's current group.
    gShare(N)		-		Sets wether or not you want to share the variables. (1/0)
    gGetShare()		N		Returns 1/0
    gSet*(S,*)		-		Sets a variable of the type '*' at index 'S' in the current group.
    gGet*(S)		*		Gets a variable of the type '*' from index 'S' in the current group.
    gSet*(N,*)		-		Exactly the same as "gSet*(N:toString(),*)"
    gGet*(N)		-		Exactly the same as "gGet*(N:toString())"
    gDelete*(S)		*		Removes and returns the variable of the type '*' at the index 'S' in the current group.
    gDelete*(N)		*		Exactly the same as gDelete*(N:toString())
    gDeleteAll*()		-		Exactly the same as gRemoveAll*() (Remember that this function is only for compatibility)
    Usage
    Here are two example E2s which show how to use the new syntax.
    Code:
    #Expression nr 1
    @inputs Button1 Button2
    @persist G:gtable
    if (first()) {G = gTable("mygroup",0)} #Get the gtable from a group, and make it non-shared (non-shared means only YOUR E2s can read & write on this table.)
    if (Button1) {G["button",number] = 1} #If the first button is pressed, set the number to 1.
    if (Button2) {G["button",number] = 2} #If the second button is pressed, set the number to 2.
    Code:
    #Expression nr 2
    @inputs Check
    @persist G:gtable
    if (first()) {G = gTable("mygroup",0)} #Get the same gtable as the first E2
    if (Check) { #When you press the check button...
        print("The last pressed button is:", G["button",number],"!") #Tell me which button was pressed on the first E2
    }
    That should clear things up!
    Last edited by Divran; 06-09-2010 at 07:16 AM.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  2. #2
    Mario, hard at work Filipe's Avatar
    Join Date
    Jun 2007
    Location
    Portugal - Lisbon
    Posts
    401
    Blog Entries
    1

    Default Re: [E2] gvar overhaul

    Already tried them out, it's an enormous improvement over the old system, awesome work, Divran!
    beep boop

  3. #3
    Wire Sofaking feha's Avatar
    Join Date
    Sep 2009
    Location
    Here
    Posts
    1,156

    Default Re: [E2] gvar overhaul

    Now someone should compare which overhaul is less laggy XD (prolly divrans).

  4. #4
    Wirererer adadr's Avatar
    Join Date
    Jan 2009
    Location
    South Dakota, USA
    Posts
    303
    Blog Entries
    3

    Default Re: [E2] gvar overhaul

    wow this makes gvars so much easier

  5. #5
    Wire Sofaking jacoby6000's Avatar
    Join Date
    Feb 2008
    Location
    behind you when you aren't looking
    Posts
    792

    Default Re: [E2] gvar overhaul

    Could you make a function to add all of the variables from a table into a gvar, so you can send it a chunk of data all at once, or from a load file.. Ex:
    Code:
    gTable("myGroup"):append(Table)
    It would add all of the indexes from table "Table" and overwrite the already used ones.
    Quote Originally Posted by Garrysmod View Post
    Warning: You're trying to render in the wrong place. This doesn't play nice with multi-core rendering, so we're not going to let you draw here.
    I'm not stupid!
    In [his] experience that was a sentence never to be uttered except to prove its own inaccuracy
    --Orson Scott Card

  6. #6
    Banned Buggzie's Avatar
    Join Date
    Dec 2009
    Location
    Under your bed
    Posts
    281
    Blog Entries
    1

    Default Re: [E2] gvar overhaul

    good job, i'm liking this, Its better than the old gGetNum gGetString etc

  7. #7
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: [E2] gvar overhaul

    Quote Originally Posted by jacoby6000 View Post
    Could you make a function to add all of the variables from a table into a gvar, so you can send it a chunk of data all at once, or from a load file.. Ex:
    Code:
    gTable("myGroup"):append(Table)
    It would add all of the indexes from table "Table" and overwrite the already used ones.
    You can simply save the table to a gvar:
    Code:
    @persist G:gtable
    if (first()) {G = gTable("mygroup",0)}
    G["mytable",table] = Table
    Edit: Later today I will fix up the Wiki and write a more thorough list of the changes. For now, enjoy the first bugfix!
    Code:
    [E2] dataSignal - Made datasignals unable to send gtables.
    [E2] gvars - Made gtables unable to save gtables to themselves.
    [E2] gvars - Added new function "gTable(S)", which works the same as "gTable(S,0)".
    [E2] gvars - Changed the name of the function called "gRemove*" to "remove*" and and "gRemoveNormal" to "removeNumber".
    Last edited by Divran; 06-09-2010 at 12:53 AM.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  8. #8
    No u Divran's Avatar
    Join Date
    Jul 2008
    Location
    Sweden
    Posts
    4,582

    Default Re: [E2] gvar overhaul

    Updated first post with a small tutorial

    EDIT: Updated wiki. Is this good? http://wiki.garrysmod.com/?title=Wir...obal_Variables
    Last edited by Divran; 06-09-2010 at 07:26 AM.
    SVN Tutorial
    My SVN:
    Code:
    http://divranspack.googlecode.com/svn/trunk/%20divranspack/
    Get dropbox and get 250 MB extra space: Dropbox

  9. #9
    Wire Sofaking jacoby6000's Avatar
    Join Date
    Feb 2008
    Location
    behind you when you aren't looking
    Posts
    792

    Default Re: [E2] gvar overhaul

    [QUOTE=Divran;196791]You can simply save the table to a gvar:
    Code:
    @persist G:gtable
    if (first()) {G = gTable("mygroup",0)}
    G["mytable",table] = Table
    What if you just wanted the values from the table there, and not the table itself? I know that you could easily extract them from the table, but one less step, right?
    Quote Originally Posted by Garrysmod View Post
    Warning: You're trying to render in the wrong place. This doesn't play nice with multi-core rendering, so we're not going to let you draw here.
    I'm not stupid!
    In [his] experience that was a sentence never to be uttered except to prove its own inaccuracy
    --Orson Scott Card

  10. #10
    Expressionism 2.0 Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,573

    Default Re: [E2] gvar overhaul

    [QUOTE=jacoby6000;197062]
    Quote Originally Posted by Divran View Post
    You can simply save the table to a gvar:
    Code:
    @persist G:gtable
    if (first()) {G = gTable("mygroup",0)}
    G["mytable",table] = Table
    What if you just wanted the values from the table there, and not the table itself? I know that you could easily extract them from the table, but one less step, right?
    Code:
    Value = gTable("mygroup",0)["mytable",table]

Closed Thread
Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
proceed-collector
proceed-collector
proceed-collector
proceed-collector
linguistic-parrots
linguistic-parrots
linguistic-parrots
linguistic-parrots