+ Reply to Thread
Results 1 to 9 of 9

Thread: Function for setting a variable from a string?

  1. #1
    Inactive Eirath245 is on a distinguished road Eirath245's Avatar
    Join Date
    Feb 2008
    Location
    England
    Posts
    210

    Default Function for setting a variable from a string?

    I've wanted this a number of times, coding both outside and inside Gmod.

    Example:
    Code:
    @name DynamicallyAssigningVariables
    @inputs Var_to_set:string   What_to_set_it_as   Set
    @persist A  B  C  D
    
    somefunctiontosetvariablehere(Vartoset, What_to_set_it_as)
    

    This would also be useful for calling particular functions (say, in Lua) based on, say, user input.

    - Jonny
    [URL="http://www.sloganizer.net/en/"][IMG]http://www.sloganizer.net/en/image,Wire,lblue,blue.png[/IMG][/URL]

  2. #2
    Newbie Programmer ZeikJT will become famous soon enough ZeikJT's Avatar
    Join Date
    Dec 2008
    Location
    California
    Posts
    1,394

    Default Re: Function for setting a variable from a string?

    You mean like the table storage there already is?
    T:setNumber("string index", number)
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

    The flame puts me in the mood to "Do it!".
    -Dart, Legend of Dragoon

  3. #3
    Expressionism 2.0

    Syranide has disabled reputation Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,504

    Default Re: Function for setting a variable from a string?

    It is not possible to dynamically set or ready variables, but as ZeikJT pointed out, you can use tables for similar effect (but it cannot be mapped to inputs or outputs).

  4. #4
    Inactive Eirath245 is on a distinguished road Eirath245's Avatar
    Join Date
    Feb 2008
    Location
    England
    Posts
    210

    Default Re: Function for setting a variable from a string?

    Quote Originally Posted by ZeikJT View Post
    You mean like the table storage there already is?
    T:setNumber("string index", number)
    I'm not just talking about Exp2, but you did give me an idea to use an enum to convert a string into a mapped integer which could be used to assign variables.


    Quote Originally Posted by Syranide View Post
    It is not possible to dynamically set or ready variables, but as ZeikJT pointed out, you can use tables for similar effect (but it cannot be mapped to inputs or outputs).
    Meh, that's why I suggested the function :P Is it actually not possible, or just not done?
    [URL="http://www.sloganizer.net/en/"][IMG]http://www.sloganizer.net/en/image,Wire,lblue,blue.png[/IMG][/URL]

  5. #5
    Newbie Programmer ZeikJT will become famous soon enough ZeikJT's Avatar
    Join Date
    Dec 2008
    Location
    California
    Posts
    1,394

    Default Re: Function for setting a variable from a string?

    Quote Originally Posted by Eirath245 View Post
    Meh, that's why I suggested the function :P Is it actually not possible, or just not done?
    I'm actually working on a global variable storage method right now, but it will have to be used minimally as it does use the global table and tables are big.

    Not dynamic variables though, just shared variables. No input/output issues.
    Last edited by ZeikJT; 01-09-2009 at 03:46 PM. Reason: adding info
    Against stupidity the Gods themselves contend in vain.
    -Friedrich Schiller

    The flame puts me in the mood to "Do it!".
    -Dart, Legend of Dragoon

  6. #6
    Expressionism 2.0

    Syranide has disabled reputation Syranide's Avatar
    Join Date
    Mar 2007
    Location
    Sweden
    Posts
    4,504

    Default Re: Function for setting a variable from a string?

    Quote Originally Posted by Eirath245 View Post
    Meh, that's why I suggested the function :P Is it actually not possible, or just not done?
    It is possible as in yes; of course it is possible... no as in; the current optimizations and "core" does not allow for it without bad sideeffects.

    Additionally, I would consider this an extremely bad philosophy, sure, for the E2 it might not matter much, but the user of a function or module should never have such influence. If you need it for serious work, you are doing it wrong or being too lazy, or you should use arrays/tables.

  7. #7
    Wire Weeaboo
    Pyro-Fire will become famous soon enough Pyro-Fire will become famous soon enough Pyro-Fire's Avatar
    Join Date
    Aug 2007
    Location
    WA, Australia
    Posts
    1,832

    Default Re: Function for setting a variable from a string?

    [ame=http://en.wikipedia.org/wiki/Eval]eval - Wikipedia, the free encyclopedia[/ame]

  8. #8
    Inactive Eirath245 is on a distinguished road Eirath245's Avatar
    Join Date
    Feb 2008
    Location
    England
    Posts
    210

    Default Re: Function for setting a variable from a string?

    Quote Originally Posted by Pyro-Fire View Post
    <3 but doesn't exist in C# >_<
    [URL="http://www.sloganizer.net/en/"][IMG]http://www.sloganizer.net/en/image,Wire,lblue,blue.png[/IMG][/URL]

  9. #9
    Wire Sofaking

    Fizyk will become famous soon enough Fizyk will become famous soon enough Fizyk's Avatar
    Join Date
    Jun 2008
    Location
    Łomianki, Poland
    Posts
    729
    Blog Entries
    1

    Default Re: Function for setting a variable from a string?

    Use CPU with ports, it's exactly what you want. You can input port number and port value and by doing out #port_number,#port_value; get the desired effect.

    My programs: BIOS - Alcyone - Calculator - Notepad - Movie Player
    My tutorials: applyTorque - Quaternions - PID controllers
    Some other things I made: FT Chip - RK4 Solar System

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 05-26-2008, 05:53 PM
  2. We need function, procedure and variable
    By Jester in forum Ideas & Suggestions
    Replies: 2
    Last Post: 05-17-2008, 12:07 PM
  3. Target finder setting problem
    By Mictaste in forum Technical Support
    Replies: 4
    Last Post: 03-23-2008, 01:38 AM
  4. Gyroscope setting.
    By Shandolum in forum Ideas & Suggestions
    Replies: 7
    Last Post: 07-11-2007, 03:22 AM
  5. Wired setting control over turrets, rangers, and such
    By Yerocrg in forum Ideas & Suggestions
    Replies: 7
    Last Post: 06-09-2007, 10:14 AM

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