Author Topic: Set multiple variables at once  (Read 18956 times)

0 Members and 1 Guest are viewing this topic.

Offline NicarTopic starter

  • Full Member
  • ***
  • Posts: 198
  • Activity:
    0%
  • Reputation Power: 0
  • Nicar has no influence.
  • Respect: +20
  • Referrals: 0
    • View Profile
Set multiple variables at once
« on: June 12, 2008, 08:39:49 AM »
0
Am I the only one that wants/uses/does this?

Like, initializing variables to 0. I don't want to check for a variable by n/a. What if I ran the script, stopped it, and I'm running it again and it is holding a value? so, now I have 5 variables, I am setting to 0... I want to set them with 1 line of code, can SUO do that?

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Set multiple variables at once
« Reply #1 on: June 12, 2008, 12:33:13 PM »
0
Am I the only one that wants/uses/does this?

Like, initializing variables to 0. I don't want to check for a variable by n/a. What if I ran the script, stopped it, and I'm running it again and it is holding a value? so, now I have 5 variables, I am setting to 0... I want to set them with 1 line of code, can SUO do that?

I've often wanted to do something exactly like that.  It really makes sense to initialize a variable to a number rather than some obscure reference that's not even a NaN or something more accepted like that.  Really, it would be pretty easy to add a system variable like #INITVAR which you can set that'll allow you set a variable initialization value. If you want to change to another block of initialization, you can just change the initializer.  I'll add that to the list of new features.
« Last Edit: June 12, 2008, 01:28:27 PM by TrailMyx »
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Hardyz

  • Jr. Member
  • **
  • Posts: 86
  • Activity:
    0%
  • Reputation Power: 0
  • Hardyz has no influence.
  • Respect: +14
  • Referrals: 0
    • View Profile
Re: Set multiple variables at once
« Reply #2 on: June 12, 2008, 02:54:35 PM »
0
Why not make a null value then :( so like %var = #null :)  I heart nulls

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Set multiple variables at once
« Reply #3 on: June 12, 2008, 04:08:47 PM »
0
Well because EUO doesn't have a real "value" for null since it deals with variable arguments mostly like strings unless math can be done.  At least with stronger typed languages, you can divine what the value should be, but you can't make the assumption with a language like EasyUO.  But if you can actually setup what you'd like "null" to be, then you get your <3 of nulls and you can talk about empty strings, zeros, N/A, etc.

Actually, if you try and do any math to a N/A, it's treated like a zero.  Also if the value that's found in a variable doesn't actually represent a number, then it's considered a zero or N/A.

Code: [Select]
set %test imanumber
set %test %test * 5 + 10
display ok %test

This will result in a 10 since the multiplication evaluates to zero.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline NicarTopic starter

  • Full Member
  • ***
  • Posts: 198
  • Activity:
    0%
  • Reputation Power: 0
  • Nicar has no influence.
  • Respect: +20
  • Referrals: 0
    • View Profile
Re: Set multiple variables at once
« Reply #4 on: June 12, 2008, 06:53:11 PM »
0
Well because EUO doesn't have a real "value" for null since it deals with variable arguments mostly like strings unless math can be done.  At least with stronger typed languages, you can divine what the value should be, but you can't make the assumption with a language like EasyUO.  But if you can actually setup what you'd like "null" to be, then you get your <3 of nulls and you can talk about empty strings, zeros, N/A, etc.

Actually, if you try and do any math to a N/A, it's treated like a zero.  Also if the value that's found in a variable doesn't actually represent a number, then it's considered a zero or N/A.

Code: [Select]
set %test imanumber
set %test %test * 5 + 10
display ok %test

This will result in a 10 since the multiplication evaluates to zero.

This all still means I'll be able to do something like
Code: [Select]
set %count1 , %count2 , %count3 , %count4 0
or

Code: [Select]
#initvar %count1 , %count2 , %count3 , %count4where it initializes to 0 or whatever?

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Set multiple variables at once
« Reply #5 on: June 12, 2008, 07:30:41 PM »
0
Well not really.  If you look an many other languages (i.e. all) there's not really a way to initialize them unless you do it by hand.  There are compiler directives that allow you to assign a null value to the respective data type (kinda like what Hardyz suggests) but mostly all of them require you to do SOMETHING with the value.

For EasyUO, you can just have faith that math on a N/A value will default to zero, i.e. set %test %test + 1 = 1.  Otherwise, it gets kinda convoluted because of EasyUO's basic typeless structure.  I'm actually having to institute a way to differentiate that since I'm wanting to include decimal math, but you also have to be able to tell the difference between 0.0 (string) and 0.0 (float).

Right now I have a hirarchy of promotion/demotion from string->int->float, but I still need to allow for a way to let the user specify this.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline NicarTopic starter

  • Full Member
  • ***
  • Posts: 198
  • Activity:
    0%
  • Reputation Power: 0
  • Nicar has no influence.
  • Respect: +20
  • Referrals: 0
    • View Profile
Re: Set multiple variables at once
« Reply #6 on: June 12, 2008, 08:12:40 PM »
0
Do I recall in C or something, a way to specify if a variable is an integer or a string? I mean, yeah, it might be a lot to put in, and could confuse/break some things, but the people that will be using it will be ones that know the project and are aware of it, and people can easily update current code to handle. Ok, so I cheated since I been out of programming for a long long time..
Code: [Select]
int x;
       float my_variable;

       x = 10;
       my_variable = -262.344;

       cout << "The value of x is " << x << endl;
       cout << "The value of my_variable is "
            << my_variable << endl;

and maybe that's what I was thinking like setting it up like   int %count1 , %count2 , ....

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Set multiple variables at once
« Reply #7 on: June 12, 2008, 08:38:30 PM »
0
Yeh, there are all kinds of constructs for various languages that allow you to specify the "type" of a variable.  I'll have to look at what matches closely enough to the EasyUO language.  I don't want this to turn into something that feels like a patchwork, so I'm going to be careful where I add to the syntax, but I still want to expand on the existing functionality.

I have to be careful because Cheffe has already created a meaning for the comma separation, and it's not for variable separation.  lol.  It's concatenation of all things.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline NicarTopic starter

  • Full Member
  • ***
  • Posts: 198
  • Activity:
    0%
  • Reputation Power: 0
  • Nicar has no influence.
  • Respect: +20
  • Referrals: 0
    • View Profile
Re: Set multiple variables at once
« Reply #8 on: June 12, 2008, 08:44:07 PM »
0
well, how about a colon ?   :  I don't think it's used for anything
Code: [Select]
int %count1 : %count2
float %realmath : %candivide

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Set multiple variables at once
« Reply #9 on: June 12, 2008, 09:01:08 PM »
0
well, how about a colon ?   :  I don't think it's used for anything
Code: [Select]
int %count1 : %count2
float %realmath : %candivide

Yeh, I was going to look at what doesn't impact EasyUO too much, and can be included in the syntax that won't mess up EasyUO itself.  But I'm scheming.. ;)
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Set multiple variables at once
« Reply #10 on: June 13, 2008, 03:31:44 AM »
0
I was thinking about your original question a bit, Nicar.  I don't think it breaks any rule to do just this:

Code: [Select]
set %count1 %count2 %count3 %count4 0

Since this breaks down into 6 tokens, I always know the first token is the command and the last token is the argument to set to (assuming 3+).  So it's actually pretty straightforward to say that tokens 1 to n - 1 should be set to the same value.

EasyUO would evaluate it a bit differently:

Code: [Select]
set %count1 %count2

the %count3 %count4 0 part would be ignored.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline NicarTopic starter

  • Full Member
  • ***
  • Posts: 198
  • Activity:
    0%
  • Reputation Power: 0
  • Nicar has no influence.
  • Respect: +20
  • Referrals: 0
    • View Profile
Re: Set multiple variables at once
« Reply #11 on: June 13, 2008, 07:31:08 AM »
0
So, perhaps, just as simple as that, it might be able to be done?

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13301
  • Activity:
    0%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Set multiple variables at once
« Reply #12 on: June 13, 2008, 10:31:41 AM »
0
So, perhaps, just as simple as that, it might be able to be done?

Yeh, I'm pretty sure I'm not going to break any existing precedence rules or any other rule for that matter.  I'll check into it.  Good idea.
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: