CreateJsonBoolean ( value )

Parameters

value - 0 stores false; any nonzero value stores true

Description

Creates an owned JSON Boolean from zero or nonzero.

The natural constructor for flags in a save file or settings document: fullscreen on, hardcore mode enabled, tutorial completed. Blitz's usual truth rule applies - 0 becomes JSON false, everything else (including True) becomes JSON true - and it serializes as a genuine JSON true or false, not as 0 or 1.

Read the value back with JsonBoolean; its kind is JSON_BOOLEAN under JsonKind. The returned handle is owned by you: release it with FreeJson. Container setters copy their input, so the usual pattern is create, set, free.

For the full rules, see the Application Data language reference.


See also: JsonBoolean, JsonKind, JsonObjectSet, CreateJsonInteger, FreeJson.

Example

; CreateJsonBoolean Example
; -------------------------

; A save-game difficulty flag: any nonzero value becomes true
hardcore=CreateJsonBoolean(True)
casual=CreateJsonBoolean(False)

Print "hardcore handle kind is JSON_BOOLEAN: "+(JsonKind(hardcore)=JSON_BOOLEAN)
Print "JsonBoolean(hardcore) = "+JsonBoolean(hardcore)
Print "JsonBoolean(casual)   = "+JsonBoolean(casual)
Print ""

; Store the flag in a save-game record to see it serialized
save=CreateJsonObject()
JsonObjectSet save,"hardcore",hardcore
Print "In a save file: "+JsonStringify(save,0)

FreeJson save
FreeJson casual
FreeJson hardcore

Print ""
Print "Press any key to close the example"
WaitKey

End

Index