One, last, crazy question - Setting a script attribute

K.V.
30 Aug 2017, 04:19

^cheat (?<text1>setscript) (?<text2>.+)$

I'd like to be able to enter:

cheat setscript box.flip => {msg ("You flip it.");box.alias = "upside-down box"}

I think it can be done by altering this:

msg ("Doing " + text2)
          regex = "(?<object>.+)\\.(?<attribute>\\S+)\\s*=\\s*(?<value>.+)"
          if (not IsRegexMatch(regex, text2)) {
            error ("Sorry, wrong format")
          }
          dict = Populate(regex, text2)
          obj = GetObject(StringDictionaryItem(dict, "object"))
          if (obj = null) {
            error ("Sorry, object not recognised")
          }
          att = StringDictionaryItem(dict, "attribute")
          value = Eval(StringDictionaryItem(dict, "value"))
          set (obj, att, value)
          msg ("Done")

The Pixie
30 Aug 2017, 06:54

As far as I know, you cannot convert a string to a script, so you cannot do it the first way. However, you can use the Eval function to run a string. I am not sure if there are limitations on that, but I think it needs to return a value, and may only cope with a single command.


K.V.
30 Aug 2017, 07:45

@ThePix

Hrmm...

msg ("Doing " + text2)
regex = "(?<object>.+)\\.(?<attribute>\\S+)\\s*=>\\s*(?<value>.+)"
if (not IsRegexMatch(regex, text2)) {
  error ("Sorry, wrong format")
}
dict = Populate(regex, text2)
obj = GetObject(StringDictionaryItem(dict, "object"))
if (obj = null) {
  error ("Sorry, object not recognised")
}
att = StringDictionaryItem(dict, "attribute")
game.value = Eval(StringDictionaryItem(dict, "value"))
obj.att => {
  game.value
}
msg ("Done")

> cheat set kv_token.push => msg ("FF")
Doing kv_token.push => msg ("FF")
Error running script: Error evaluating expression 'Eval(StringDictionaryItem(dict, "value"))': Error compiling expression 'msg ("FF")': FunctionCallElement: Could find not function 'msg(String)'

> cheat set kv_token.push => {msg ("FF")}
Doing kv_token.push => {msg ("FF")}
Error running script: Error evaluating expression 'Eval(StringDictionaryItem(dict, "value"))': Error compiling expression '{msg ("FF")}': SyntaxError: Unexpected character: {Line: 1, Column: 1Unexpected character: }Line: 1, Column: 12

I think this one's pretty awesome. (Hehehe)

We just invented a calculator:

> cheat set kv_token.pull => 1 + 2
Doing kv_token.pull => 1 + 2
3
Error running script: Function not found: 'game.value'


mrangel
30 Aug 2017, 22:33

Maybe ... hmm …

setscriptcommand = obj.name + "." + att + " => {" + StringDictionaryItem(dict, "value") + "}"
Eval (setscriptcommand)

or something along those lines?
So you're eval'ing the whole "obj.attr => { msg(something) }" block. Haven't tried using Eval, but that would be my first attempt at making it do what I think you're aiming for.

or just

Eval (text2)

K.V.
01 Sept 2017, 21:50

I don't know if I'm getting colder or warmer, but I'd be inclined to bet that Pixie would have already found a way to convert a string to a script if it could be done.


Eval doesn't like 'value':

msg ("Enter the your one line script now. Example:#object#.#attribute# =>  @@@open@@@msg (\"Hello, Forum!\")@@@close@@@<br/>")
get input {
  msg ("Doing " + result)
  regex = "(?<object>.+)\\.(?<attribute>\\S+)\\s*=>\\s*(?<value>.+)"
  if (not IsRegexMatch(regex, result)) {
    error ("Sorry, wrong format")
  }
  dict = Populate(regex, result)
  msg (dict)
  obj = GetObject(StringDictionaryItem(dict, "object"))
  if (obj = null) {
    error ("Sorry, object not recognised")
  }
  att = StringDictionaryItem(dict, "attribute")
  value = Eval(StringDictionaryItem(dict, "value"))
  msg (obj)
  msg ("att: " + att)
  msg ("value: " + value)

...the script continues, but it has already thrown an error.

> script
Enter the your one line script now. Example:#object#.#attribute# => {msg ("Hello, Forum!")}

Doing box.jump => msg ("hello")
Dictionary: object = box;attribute = jump;value = msg ("hello")
Error running script: Error evaluating expression 'Eval(StringDictionaryItem(dict, "value"))': Error compiling expression 'msg ("hello")': FunctionCallElement: Could find not function 'msg(String)'


This seems to get a little closer:

msg ("Enter the your one line script now. Example:#object#.#attribute# =>  @@@open@@@msg (\"Hello, Forum!\")@@@close@@@<br/>")
get input {
  msg ("Doing " + result)
  regex = "(?<object>.+)\\.(?<attribute>\\S+)\\s*=>\\s*(?<value>.+)"
  if (not IsRegexMatch(regex, result)) {
    error ("Sorry, wrong format")
  }
  dict = Populate(regex, result)
  msg (dict)
  obj = GetObject(StringDictionaryItem(dict, "object"))
  if (obj = null) {
    error ("Sorry, object not recognised")
  }
  att = StringDictionaryItem(dict, "attribute")
  value = StringDictionaryItem(dict, "value")
  msg (obj)
  msg ("att: " + att)
  msg ("value: " + value)
  
  set (obj, att, value)
  //At this point, obj.att is set up with whatever value holds as the string.
  setscriptcommand = obj.name + "." + att + " => {" + StringDictionaryItem(dict, "value") + "}"
  msg ("setscriptcommand: " + setscriptcommand)
  objatt = obj.name + "." + att
  msg ("objatt: " + objatt)
  objattdict = NewScriptDictionary()
  msg ("objattdict: " + objattdict)
  valuescript => value
  msg ("valuescript: " + valuescript)
  dictionary add (objattdict, att, valuescript))
  msg ("objattdict: " + objattdict)
  msg ("ScriptDictionaryItem(objattdict, att): " + ScriptDictionaryItem(objattdict, att))
  msg ("Done")

}

> script
Enter the your one line script now. Example:#object#.#attribute# => {msg ("Hello, Forum!")}

Doing box.push => msg ("HELLO")
Dictionary: object = box;attribute = push;value = msg ("HELLO")
Object: box
att: push
value: msg ("HELLO")
setscriptcommand: box.push => {msg ("HELLO")}
objatt: box.push
objattdict: Dictionary:
valuescript: { value }
objattdict: Dictionary: push = { value }
ScriptDictionaryItem(objattdict, att): { value }
Done

> push box
msg ("HELLO")


obj.att

This creates box.att. Hehehe.

And it doesn't like obj.+ att or obj." + att + "...

That's why I changed the line to value = StringDictionaryItem(dict, "value") and made it a string attribute first with set (obj, att, value) (which is directly from the SET case in Pixie's cheat script).

I thought I could just make that a NewScriptDictionary afterwards, but I'd still need to use obj.att to pull it off.

...unless I used a Switch script, and utilized foreach (cmd, AllCommands()) to add each available verb as a CASE...

case ("push") {
  obj.push => value
}

That probably still wouldn't work though...


hegemonkhan
02 Sept 2017, 00:17

this is way beyond my ability already, KV, and thus I'm not really able to follow along with it... but...

have you tried...

do (obj, att, value)

or maybe...

do (obj, att, Eval (value))

or maybe....

evaluate_variable = Eval (value)
do (obj, att, evaluate_variable)

or maybe....

script_variable => { Eval (value) }
do (obj, att, script_variable)

or maybe....

evaluate_variable = Eval (value)
script_variable => { evaluate_variable }
do (obj, att, script_variable)

or maybe....

script_variable => Eval ("{" + value + "}")
do (obj, att, script_variable)


K.V.
02 Sept 2017, 04:06

I tried all of those but script_variable => Eval ("{" + value + "}"), but it doesn't like that either:

/> script
Enter the your one line script now. Example:#object#.#attribute# => {msg ("Hello, Forum!")}

Doing box.push => msg ("HELLO")
Dictionary: object = box;attribute = push;value = msg ("HELLO")
Object: box
att: push
value: { Eval ("{" + value + "}") }
Error running script: Function not found: 'Eval'


As far as I know, you cannot convert a string to a script, so you cannot do it the first way. However, you can use the Eval function to run a string. I am not sure if there are limitations on that, but I think it needs to return a value, and may only cope with a single command.

box.push => msg ("NO!")

obj = GetObject(StringDictionaryItem(dict, "object"))

Object = box

att = StringDictionaryItem(dict, "attribute")

att = push

value = Eval(StringDictionaryItem(dict, "value"))

value = msg ("NO!")

But:

obj.att => msg ("NO!")

I get box.att which returns the string "msg ("NO!")"

set (box, att, value)

I get:

box.push which returns the string "msg ("NO!")"


I just had one more idea:

#object#.#text1# => #text2#

msg (object)
msg (text1)
msg (text2)
object.text1 => {
  msg (text2)
}

Ha! This sets it as a script! It doesn't put text2 in there, but it's a little bit of progress; right?

image


Now, title1 is the problem...

I'm gonna try

set (object, title1, value)

Now, if there's a way to create a new script dictionary without having to use the object.attribute = NewScriptDictionary() format, I bet we may be able to do this!


UPDATE

The box.text1 attribute was a string that displayed "Script: msg (text1)".

Ha! That's funny!

I give up.

(Should have listened to ThePix in the first place...)

Thanks for all the help though, everyone!


hegemonkhan
02 Sept 2017, 07:37
I get box.att which returns the string "msg ("NO!")"

set (box, att, value)

I get:

box.push which returns the string "msg ("NO!")"

(by KV)

maybe try this:

Eval (box.push)

or this:

invoke (box.push)

or this:

do (box, "push")

or this:

do (box, "push", value)


"(Should have listened to ThePix in the first place...) (KV)"

ya, but it'd be cool to figure out how to do something that Pixie couldn't .... if only we could though... failure so far...


and I forgot that the 'msg' Function is special, as there's all of the underlying and/or built-in coding for it (as it can be seen as a String Value or as a Script Value). The 'msg' Function is kinda like a universal/general/super Function, maybe the 'Eval' Function is programmed into the 'msg' Function...

So, maybe you're on to something... maybe you can figure it out via some way of using the 'msg' Function.


P.S.

also, noticed within your post about a Script Dictionary:

why not just use a Script Dictionary (if it can work)?

// obj = box
// att = "push"
// value => { msg ("hello") }
set (obj, att, value) // box.push = "msg ("hello")"
set (obj, "script_dictionary_attribute", value)
do (obj, "script_dictionary_attribute")


actually.. why doesn't/wouldn't this work?

obj = box
att = "push"
text = "msg ("hello")"
value => { text }
set (obj, att, value)
do (obj, att)

or maybe this:

obj = box
att = "push"
text = "msg ("hello")"
string_variable = "{" + text + "}"
value => string_variable
set (obj, att, value)
do (obj, att)


Lastly....

Jay found a trick where you can use a 2nd Dictionary as a VARIABLE for/within your 1st Dictionary, which awesomely-somehow causes the 2nd Dictionary's 'keys' and 'values' to be VARIABLES/Parameters that can be used by the 1st Dictionary's scripting...

maybe you could use this for getting a string into a script...


K.V.
02 Sept 2017, 08:12

HK,

Yeah... I tried all those, unfortunately.

...and here's the dictionary bits that work with strings but not scripts:

msg (obj)
  msg ("att: " + att)
  msg ("value: " + value)
  
  set (obj, att, value)
  //At this point, obj.att is set up with whatever value holds as the string.
  setscriptcommand = obj.name + "." + att + " => {" + StringDictionaryItem(dict, "value") + "}"
  msg ("setscriptcommand: " + setscriptcommand)
  objatt = obj.name + "." + att
  msg ("objatt: " + objatt)
  objattdict = NewScriptDictionary()
  msg ("objattdict: " + objattdict)
  valuescript => value
  msg ("valuescript: " + valuescript)
  dictionary add (objattdict, att, valuescript))
  msg ("objattdict: " + objattdict)
  msg ("ScriptDictionaryItem(objattdict, att): " + ScriptDictionaryItem(objattdict, att))

Eval seems to just return a string, too, but I honestly have no idea what the heck Eval is doing!

I know it can display a string and perform mathematical operations. It doesn't seem to like the string within msg ("WHATEVER") though...


I can too post this here!!!


K.V.
02 Sept 2017, 08:17

Jay found a trick where you can use a 2nd Dictionary as a VARIABLE for/within your 1st Dictionary, which awesomely-somehow causes the 2nd Dictionary's 'keys' and 'values' to be VARIABLES/Parameters that can be used by the 1st Dictionary's scripting...

That guy was crazier than I am! (Plus, he seemed to know what the hell he was doing!)

If you find a post with Jay and Pixie collaborating on something, just go on ahead and download/copy & paste everything towards the bottom of the thread, because that stuff is ALWAYS awesome!


I've been wondering if there's a way to download all of the old forum attachments. I found the folder's URL, but I never ran the BASH! script that would download the entire directory. (I'd hate to overload the server. Plus, there's NO TELLING what all I'd end up with! Probably more screenshots than anything...)



BUT...

I already stole that trick from Pixie's CHEAT SET script:

regex = "(?<object>.+)\\.(?<attribute>\\S+)\\s*=>\\s*(?<value>.+)"
  if (not IsRegexMatch(regex, result)) {
    error ("Sorry, wrong format")
  }
  dict = Populate(regex, result)
  msg (dict)
  obj = GetObject(StringDictionaryItem(dict, "object"))
  if (obj = null) {
    error ("Sorry, object not recognised")
  }
  att = StringDictionaryItem(dict, "attribute")
  value = StringDictionaryItem(dict, "value")
  msg (obj)
  msg ("att: " + att)
  msg ("value: " + value)
  //All of these print out correctly.
  set (obj, att, value)
  //At this point, obj.att is set up with whatever its value holds as the string.

Now, at this point, if att is an actual command or verb (like push), you can enter PUSH BOX and it will print the string like you set it up to give a text only response.

Maybe populating a Script Dictionary with value is the key...


hegemonkhan
02 Sept 2017, 08:45

script_variable => { msg ("hello") }
script_dictionarys_items_key_value_string_variable = "1 = " + script_variable
set (obj, "script_dictionary_attribute", script_dictionarys_items_key_value_string_variable)
do (obj, "script_dictionary_attribute", "1")

or:

string_variable = "msg (" + "hello" + ")"
script_dictionarys_items_key_value_string_variable = "1 = " + string_variable
set (obj, "script_dictionary_attribute", script_dictionarys_items_key_value_string_variable)
do (obj, "script_dictionary_attribute", "1")


or, if you can't use 'set' to create a Script Dictionary:

--

script_variable => { msg ("hello") }
script_dictionarys_items_key_value_string_variable = "1 = " + script_variable
box.script_dictionary_attribute = NewScriptDictionary ()
dictionary add (box.script_dictionary_attribute, script_dictionarys_items_key_value_string_variable)
do (box, "script_dictionary_attribute", "1") // or: invoke (box.script_dictionary_attribute, "1")

or:

string_variable = "msg (" + "hello" + ")"
script_dictionarys_items_key_value_string_variable = "1 = " + string_variable
box.script_dictionary_attribute = NewScriptDictionary ()
dictionary add (box.script_dictionary_attribute, script_dictionarys_items_key_value_string_variable)
do (box, "script_dictionary_attribute", "1") // or: invoke (box.script_dictionary_attribute, "1")