breakfunc-continuefunc command

Feature requests for future versions of Hollywood can be voiced here
Post Reply
Bugala
Posts: 691
Joined: Sun Feb 14, 2010 8:11 pm

breakfunc-continuefunc command

Post by Bugala » Sat Aug 18, 2018 10:29 pm

after notice: Seems I wasnt able to make this very clear. If it seems difficult to undersatnd, i will send you simpler version.

To get this idea better, is to explain real case situation.

I am making this card game just to practice some new coding technics, and there is constantly one problem that i encounter all the time which makes the code very messy.

Situation is this.
1. Player chooses to build one of his cards.
2. After choosing which card to build, he needs to choose which cards to use to pay it.
3. in case payment is not exact payment, he needs to choose which cards to take as change (basically, if you buy 2 euro stuff, and you pay with 5 euro sedel, you then get to choose what kind of change to get back.

As I am trying to do this all using WaitEvent() system, I cant really figure out how to do this any simple and clean way, but I have to make several functions:

Code: Select all

Function makebuildablecardspickable
foreach card
	if card = buildable card then card.leftmousebuttonfunction=pickingbuildingcard
next
endfunction

function pickingbuildingcard
	resetcardsleftmousefunctions()
	makepricecardschoosable()
	price = card.price
endfunction

function resetcardsleftmousefunction()
foreach card
	card.leftmousebuttonfunction = fefaultfunction
next
endfunction

function makepricecardschoosable()
foreach card
	if card = pricecard then card.leftmousebuttonfunction=payabuilding
next
endfunction

function payabuilding
price = price - card.price
if price = 0 donepaying
if price < 0 then getchange
endfunction

function getchange
---
endfunction
a whole load of trouble and load of functions.

What I would like to be able to do, would be soemthing like this:

Code: Select all

Function BuildABuilding
foreach card
	if card = buildable card then card.leftmousebuttonfunction=pickingbuildingcard
next

breakfunc(1)

resetcardsleftmousefunctions()
makepricecardschoosable()
price = card.price
endfunction

breakfunc(1)

price = price - card.price
if price = 0 donepaying
if price < 0 then getchange

endfunction



function pickingbuildingcard()
continuefunc(1)
endfunction

function payabuilding
continuefunc(1)
endfunction

function 
I guess you can see the benefit yourself about how much easier this code is to read and find out what is happening in that building buying place, than the previous one where first part of things happen in first function, next part in next function etc. With this everything can basically happen in this one function only, so you only need to read that one function through to figure out what is happening there, instead of keep jumping from one function to next to see what is happening.

Would this be doable?

SamuraiCrow
Posts: 171
Joined: Fri May 15, 2015 5:15 pm
Location: Ft. Collins, Colorado USA

Re: breakfunc-continuefunc command

Post by SamuraiCrow » Sun Aug 19, 2018 2:19 am

I still don't quite get what you're trying to do. Would passing function references as parameters help here?

Bugala
Posts: 691
Joined: Sun Feb 14, 2010 8:11 pm

Re: breakfunc-continuefunc command

Post by Bugala » Mon Aug 20, 2018 10:46 am

Okay, here is simpler verision of what I am after (I dont think showing the real case was good idea, since it was too ahrd o understand it).

Lets make a simple thinkg like this (with pseudo code again)

Code: Select all

Function ChooseBoxAndReact()
DisplayText("Choose One of the Boxes")
-at this point user chooses one box by clicking on it-
If box = "red" 
	displaytext("you chose a red box")
elseif box = "blue"
        displaytext("you chose a blue box")
endif
endfunction
Now this would be the ideal case. However, because user actually needs to click one of the boxes, when using waitevent(), in practice code like this becomes more like

Code: Select all

function ChooseBox()
Displaytext("Choose One of the Boxes")
endfunction

function boxclick(msg) */ this be the one that would be attached to the box for left mouse button click */
color = msg.variable
BoxClicked(color)
endfunction

function boxclicked(color)
displaytext("You chose a "..color.." box")
endfunction
So basically using waitevent, this one function have to be divided in to two parts, that instead of having one function that shows clearly what is happening, for someone else to know what is happening in code, would need to figure out first that there comes part you need to click those boxes, and then you have to find out "makebutton" command to see what function is being called after that button is clicked, and then finally check that function. And in my real life case this had to be repeated more than once making it very messy.

You could basically use same function with variables, but that would result in bit of a messy case too:

Code: Select all

ChooseBoxAndReact(state, color, maybe more vars)
if state = "choose"
 DisplayText = "Choose One of the boxes"
elseif state = "chosen"
 displaytext("You chose a "..color.." box")
endif
endfunction
This works fine in this example still, but lets just say that each box does a different thing, and code already gets slightly messier (not badly yet):

Code: Select all

ChooseBoxAndReact(state, color, maybe more vars)
if state = "choose"
 DisplayText = "Choose One of the boxes"
elseif state = "chosen"
	if color="red"
 		displaytext("You chose a red box")
 	elseif color="blue"
 	       displaytext("you chose a blue box")
 	 endif
endif
endfunction
But you can anyway start seeing that especially in my previous real case example, there are going to be more states than just these, and there are more stuff happening making it harder and harder to read and make. It becomes very easy to make a mistake that messes everything with so many variables to follow, and on top of that, depending upon the case, it is not neecssarily clear in what order those states will be executed. That in this case it is clear, first you choose a box, and then happens the result, but sometimes choices can branch, making it so that not all states will be executed at all during one execution.

As simple example, state "pick heart, cross, diamond or spade", then each individual card comes out of it as "space ace, spade 2, spade 3...", this is bit bad example in sense that you could just pick number next, but supposing you actually have to make it that way that each card is it own entry, then in this case for example state "diamond" would not be executed at all if user doesnt choose it, yet it shows up in that function. and it might be difficult following how it goes.

Hence It would be handy if i could:

Code: Select all

ChooseBoxAndReact()
DisplayText = "Choose One of the boxes"

breakfunc(1, chosencolor)

switch chosencolor
	if chosencolor="red"
 		displaytext("You chose a red box")
 	elseif chosen="blue"
 	       displaytext("you chose a blue box")
 	 endif
endif
endfunction

makebutton(... OnLeftMouse=function continuefunc(1, chosencolor=red) endfunction)

Post Reply