StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
jackhab  
#1 Posted : Sunday, December 3, 2023 3:39:29 PM(UTC)
jackhab

Rank: Newbie

Reputation:

Groups: Approved
Joined: 7/6/2020(UTC)
Posts: 9
Israel

Thanks: 1 times
I'm trying to write a script function which accepts hotkeys and, among other things, displays hotkey names to user.

I'm not sure if this is because my limited knowledge of JS but I don't understand why I can't get the same value as printed to console into a variable.

Code:
sp.ConsoleLog(vk.ACCEPT) //Output: "ACCEPT"

var key = ""
key = "key " + JSON.stringify(vk.ACCEPT) 
sp.ConsoleLog(key)  //Output: "key {}"

var key = ""
key = "key " + vk.ACCEPT.toString()
sp.ConsoleLog(key)  //Output: [object Object]



How can I store vk value as a string in a variable?

Edited by user Sunday, December 3, 2023 6:56:50 PM(UTC)  | Reason: Not specified

Rob  
#2 Posted : Sunday, December 3, 2023 4:57:50 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,360
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 420 time(s) in 357 post(s)
Here you go.

Code:
var names = [];
var vks = System.Enum.GetNames(host.typeOf(vk));
for (var i = 0; i < vks.Length; i++) {
    names.push(vks[i]);
}
sp.ConsoleLog(JSON.stringify(names.sort()));
Rob  
#3 Posted : Sunday, December 3, 2023 5:00:54 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,360
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 420 time(s) in 357 post(s)
Also, you can use the .NET ToString() method on an individual one, not the JavaScript toString() version.
Code:
StrokesPlus.Console.Log(vk.ACCEPT.ToString());

StrokesPlus.Console.Log(JSON.stringify(vk.ACCEPT.ToString()));

Edited by user Sunday, December 3, 2023 5:01:37 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
jackhab on 12/3/2023(UTC)
jackhab  
#4 Posted : Sunday, December 3, 2023 6:56:19 PM(UTC)
jackhab

Rank: Newbie

Reputation:

Groups: Approved
Joined: 7/6/2020(UTC)
Posts: 9
Israel

Thanks: 1 times
Originally Posted by: Rob Go to Quoted Post
Also, you can use the .NET ToString() method on an individual one, not the JavaScript toString() version.
Code:
StrokesPlus.Console.Log(vk.ACCEPT.ToString());

StrokesPlus.Console.Log(JSON.stringify(vk.ACCEPT.ToString()));


Thanks a lot , Rob. I totally forgot it's all .Net based.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.