Skip to content

Using floats as arguments for functions expecting shorts or longs results in unexpected behavior #13

@brentcklein

Description

@brentcklein

Doing something like:

float discount
float salePrice

set discount to ( 0.4 )
set salePrice to ( 100 * discount )
Player->xAddItem, "Gold_001", salePrice

results in a the max stack of 180k gold being added to the player's inventory. It appears this has something to do with the way MWSE attemps to convert between variable types; similar unexpected behavior can be observed when logging messages, eg:

short do
float num

if ( do != 0 )
    return
endif

set num to ( 0.5 )
xLogMessage "this is NOT the expected outcome: %d", num
xLogMessage "this IS the expected outcome: %.1f", num

set do to 1

results in this output:

this is NOT the expected output: 1056964608
this IS the expected output: 0.5

This prevents any operations involving floats with arguments that will eventually be passed to functions that expect short or long, which is especially relevant when dealing with prices.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions