SetKeyValue hint

Post new mods and scenarios here.

Moderator: MOD_Command

Post Reply
mx1
Posts: 76
Joined: Thu Jan 16, 2014 6:01 pm

SetKeyValue hint

Post by mx1 »

I've just lost half an hour trying to figure this out so decided to write a hint for all scenario developers using Lua. The ScenEdit_GetKeyValue() function returns string, so before using the stored value in numerical context it needs to be explicitly converted to number via tonumber() function, even if value stored by ScenEdit_SetKeyValue() was numeric. I think it should be noted in the API documentation.
Tomcat84
Posts: 1952
Joined: Wed Jul 10, 2013 5:13 pm

RE: SetKeyValue hint

Post by Tomcat84 »

Yep

Pretty sure I touched on this in my 2nd Lua tutorial:

tm.asp?m=3755831


but it is definitely important.
My Scenarios and Tutorials for Command

(Scenarios focus on air-warfare :) )
ckfinite
Posts: 208
Joined: Fri Jul 19, 2013 10:33 pm

RE: SetKeyValue hint

Post by ckfinite »

I wrote a library for this. What it lets you do is write code like:
KeyStore.number = 2
KeyStore.string = "Hello!"
KeyStore.array = {1,2,3,4}
KeyStore.table = {a = 2, b = 3}

And it'll keep track of what is what, so they work like you expect them too.

Find it here: https://github.com/BenChung/CKLibs/blob ... stUtil.lua
Post Reply

Return to “Mods and Scenarios”