Author Topic: Dynamic variables  (Read 2479 times)

0 Members and 1 Guest are viewing this topic.

Offline PearlsTopic starter

  • Hero Member
  • *
  • Posts: 557
  • Activity:
    0%
  • Reputation Power: 13
  • Pearls barely matters.Pearls barely matters.
  • Respect: +65
  • Referrals: 1
    • View Profile
Dynamic variables
« on: July 10, 2014, 10:32:58 AM »
0
Why does the first example work while the second one doesn't?


Here i set a namespace variable !dynamic to the concatenated result of 'carpentry' and '_crafting_gump_resource'.

Code: [Select]
set !resource iron
set !gump_type carpentry
set !dynamic !gump_type , _crafting_gump_resource ; !dynamic = string 'carpentry_crafting_gump_resource'
display % . !dynamic ; N/A = which is what i'm looking for


I want to check if the dynamic variable has ever been set before by checking if it's N/A.
I want it to be "if %carpentry_crafting_gump_resource = N/A"

Code: [Select]
set !resource iron
set !gump_type carpentry
if % . ( !gump_type , _crafting_gump_resource ) = N/A ; this makes a string %(carpentry_crafting_gump_resource)
{
  set % . ( !gump_type , _crafting_gump_resource ) !resource
  display %carpentry_crafting_gump_resource
}
halt
« Last Edit: July 10, 2014, 11:00:32 AM by Pearls »
XII : "My happiness as a married man is directly related to the amount of sex I have which, in turn, requires that I pretend I like these movies every now and then and that it really doesn't bother me when she tells me about her problems but doesn't want me to give her a solution ;) "

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • 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: Dynamic variables
« Reply #1 on: July 10, 2014, 11:49:56 AM »
0
You'll find that the presidence doesn't work really well in EUO with regards to parenthesis.  I'm sure there's an accurate explanation, but I never really got comfortable with the internal mechanics. 

To get your example to work (hopefully, not tested) you need an interim step:

Code: [Select]
set !resource iron
set !gump_type carpentry
set !temp_str !gump_type , _crafting_gump_resource
if % . !temp_str = N/A ; this makes a string %(carpentry_crafting_gump_resource)
{
  set % . !temp_str  !resource
  display %carpentry_crafting_gump_resource
}
halt
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline PearlsTopic starter

  • Hero Member
  • *
  • Posts: 557
  • Activity:
    0%
  • Reputation Power: 13
  • Pearls barely matters.Pearls barely matters.
  • Respect: +65
  • Referrals: 1
    • View Profile
Re: Dynamic variables
« Reply #2 on: July 10, 2014, 12:23:26 PM »
0
Aye that's exactly what i've been using as a temporary solution :) Guess it's permanent now hehe.
Thx
XII : "My happiness as a married man is directly related to the amount of sex I have which, in turn, requires that I pretend I like these movies every now and then and that it really doesn't bother me when she tells me about her problems but doesn't want me to give her a solution ;) "

Offline manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Dynamic variables
« Reply #3 on: July 10, 2014, 05:15:28 PM »
0
Rearrange the Order. When you are building arrays with EUO you always want the Part that Changes to be at the End .

set %Resource1
set %Resource2
set %REsource3  etc etc etc

So in your case you had

set %Carpentry_Crafting_Gump_Resource

with Carpentry being the part that Changes, so move that to the end instead of the Beginning.
%Crafting_Gump_Resource_Carpentry

set !resource iron
set !gump_type carpentry
set %Crafting_Gump_Resource_ , !Gump_Type !Resource
  display %Crafting_Gump_Resource_Carpentry
halt
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

Offline PearlsTopic starter

  • Hero Member
  • *
  • Posts: 557
  • Activity:
    0%
  • Reputation Power: 13
  • Pearls barely matters.Pearls barely matters.
  • Respect: +65
  • Referrals: 1
    • View Profile
Re: Dynamic variables
« Reply #4 on: July 11, 2014, 05:21:09 AM »
0
Actually i'm already using the array as you mention:

Code: [Select]
  set %dynamic_gump_makelast !gump_type , _crafting_gump_makelast
  if % . %dynamic_gump_makelast = N/A || % . %dynamic_gump_makelast <> !item_type
  {
    ; check if we need to set the resource type
    set %dynamic_gump_resource !gump_type , _crafting_gump_resource
    if % . %dynamic_gump_resource = N/A || % . %dynamic_gump_resource <> !resource
    {
      set % . %dynamic_gump_resource !resource
      gosub PEARLS_craft_set_resource !resource
    }
    ; check if we need to set the category
    set %dynamic_gump_category !gump_type , _crafting_gump_category
    if % . %dynamic_gump_category = N/A || % . %dynamic_gump_category <> !category
    {
      set % . %dynamic_gump_category !category
      gosub PEARLS_craft_set_category !category
    }
    ; we always need to set page, so if page is not 1, set it :D
    set %dynamic_gump_page !gump_type , _crafting_gump_page
    if % . %dynamic_gump_page = N/A || % . %dynamic_gump_page <> !page
    {
      set % . %dynamic_gump_category !category
    }
    if !page > 1
    {
      gosub PEARLS_craft_set_page !page
    }
    set % . %dynamic_gump_makelast !item_type
    set % . %dynamic_gump_selection !selection
    gosub PEARLS_craft_set_item !selection
  }
  else
  {
    gosub PEARLS_craft_makelast
  }

Basically a way of storing information on each crafting gump you have worked with to remember if you are making last item, what page, etc...
It's part of the first script i've ever written so it's a learning process hehe :D Once the script is ready for testing, i'll post it on the site :D
XII : "My happiness as a married man is directly related to the amount of sex I have which, in turn, requires that I pretend I like these movies every now and then and that it really doesn't bother me when she tells me about her problems but doesn't want me to give her a solution ;) "

Tags: