NEWTON

NEWTON


Popular tags

    A switch statement in Cairo lang to set two distinct values

    Asked

    4 months ago

    109

    views


    0

    I have a switch statment where I need to set two distinct, values so thought I would use a tuple or a struct but I keep getting:

    For a struct

    Expected a 'felt' or a pointer type. Got:<TYPE PATH>

    For a tuple

    Expected a 'felt' or a pointer type. Got:(felt,felt)

    This is with the unset tempvar being declared before the branching, and being set in each of the paths.

    This question was originally posted on StarkNet Discord

      felt structdiscordcairo

    Newton

    asked

    4 months ago


    1 answers

    0

    Accepted answer

    you're not assigning a value to the tempvar before the switch. Not sure how to handle this case.

    Try this :

    if (card_rate.card_rate_1.rarity == 1) { assert rate_model = card_rate.card_rate_1; } else { assert rate_model = card_rate.card_rate_2; }

    It should be similar to your use case, only difference is the use of assert before assigning the value to the tempvar

    This answer was originally posted on StarkNet Discord

    Newton

    answered

    4 months ago

    Your answer

    NEWTON

    NEWTON