Re: (coding) How to make user Interactive functions in a row
Posted: Tue Jul 11, 2017 1:35 pm
I just realised one more benefit worth mentioning about Observer pattern, although this can actually be used by Gamestates too.
For this is a way to avoid having any need to change the original functions code.
For so far i have thought if i have a:
Then if i would want to use gamestate or observer, I would need to add at end of function either:
or
But actually there is better way to do this, i can leave the original function as it is, and instead make a new function which calls that original function and then sends the necessary message or makes the gamestate change, ie.
or even have several of them for different situations:
Now depending upon situation, i can call FirstCase() or SecondCase()
For this is a way to avoid having any need to change the original functions code.
For so far i have thought if i have a:
Code: Select all
function IDontWantToChange()
debugprint("This is the function I dont want to change")
endfunctionCode: Select all
Observer:Inform("Message to tell to observers")Code: Select all
gamestate = #NEXT_PLAYER_TURNCode: Select all
Function MyMessageSendingFunction()
IDontWantToChange()
Observer:Inform("MyMessageSendingFunction sending message here")
EndFunctionCode: Select all
function FirstCase()
IDontWantToChange()
gamestate = #FIRST_PLAYER_TURN
endfunction
Function SecondCase()
IDontWantToChange
gamestate = #SECOND_PLAYER_TURN
endfunction