making code wait on Input
Post MTG Forge Related Programming Questions Here
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
11 posts
• Page 1 of 1
making code wait on Input
by slapshot5 » 04 Jul 2011, 14:25
Hi all,
I know I've run across this before, but don't remember if I solved it.
Basically, I have:
What actually happens is showMessage() for discard, card is drawn, now I can Input my discard (and discard the card that was drawn, which is incorrect).
Do we have a way to do this correctly?
Thanks,
slapshot5
I know I've run across this before, but don't remember if I solved it.
Basically, I have:
- Code: Select all
public void resolve() {
player.discard();
player.drawCard();
}
What actually happens is showMessage() for discard, card is drawn, now I can Input my discard (and discard the card that was drawn, which is incorrect).
Do we have a way to do this correctly?
Thanks,
slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
Re: making code wait on Input
by friarsol » 04 Jul 2011, 14:37
I don't believe this exists currently. It would be great if it did, because there are definitely some other timing issues related to anything that resolves with a Custom Input.
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: making code wait on Input
by Hellfish » 04 Jul 2011, 15:28
As far as I understand the Input system, there is no way to do this save for modifying the Input base class to contain a Command object that can be run when the Input's stop() method is called.
FAKE EDIT: I don't think you could mod InputControl to do such a thing, but it's possible.
FAKE EDIT: I don't think you could mod InputControl to do such a thing, but it's possible.
So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: making code wait on Input
by Braids » 07 Jul 2011, 14:35
my understanding of the code is shaky, but maybe you could consider one of these?slapshot5 wrote:. . . What needs to happen is the discard happens, then the draw . . . Do we have a way to do this correctly?
- extend the Input for discarding a card so that, during its custom resolution method {selectCard i think}, call super's version of selectCard, then draw the card.
- use the MagicStack. push a draw action/trigger/whatever, then immediately push the discard action. this is fairly elegant, but it violates atomicity/inseverability/indivisibility of the card's resolution. either player could respond after the discard, before the draw. i don't think that's supposed to happen.
- i seem to recall some references to an Input stack. this is an Input stack, not a MagicStack.
does it work? if it is supported, perhaps you could push a dummy Input for drawing a card that calls its own selectX method from showMessage, then push the one for discarding. then they resolve in reverse order.
edit 1: fixed list tag.
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. 

-
Braids - Programmer
- Posts: 556
- Joined: 22 Jun 2011, 00:39
- Location: Unknown. Hobby: Driving myself and others to constructive madness.
- Has thanked: 1 time
- Been thanked: 1 time
Pipe dreaming Re: making code wait on Input
by Braids » 07 Jul 2011, 14:41
slapshot5 wrote:
- Code: Select all
public void resolve() {
player.discard();
player.drawCard();
}
- Code: Select all
public void resolve() {
final Player finalPlayer = player;
Thunk<Null> drawThunk = new Thunk<Null> {
public Null apply() { finalPlayer.drawCard(); return null; }
};
player.discardThen(drawThunk);
}
there are thunks and lambdas on the minimax branch.

edit 1: fixed bugs in code

edit 2: fixed typo
edit 3: improved indentation
Last edited by Braids on 07 Jul 2011, 14:47, edited 1 time in total.
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. 

-
Braids - Programmer
- Posts: 556
- Joined: 22 Jun 2011, 00:39
- Location: Unknown. Hobby: Driving myself and others to constructive madness.
- Has thanked: 1 time
- Been thanked: 1 time
Re: making code wait on Input
by Hellfish » 07 Jul 2011, 14:46
So it's like a Command object with a return type? 

So now you're
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
Screaming for the blood of the cookie monster
Evil puppet demon of obesity
Time to change the tune of his fearful ballad
C is for "Lettuce," that's good enough for me
-
Hellfish - Programmer
- Posts: 1297
- Joined: 07 Jun 2009, 10:41
- Location: South of the Pumphouse
- Has thanked: 110 times
- Been thanked: 169 times
Re: making code wait on Input
by Braids » 07 Jul 2011, 14:48
yes. yes, it is. Null is a special class that cannot be instantiated by anyone ever, so about the only value it can take on is an actual {null}.
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. 

-
Braids - Programmer
- Posts: 556
- Joined: 22 Jun 2011, 00:39
- Location: Unknown. Hobby: Driving myself and others to constructive madness.
- Has thanked: 1 time
- Been thanked: 1 time
Re: making code wait on Input
by Rob Cashwalker » 08 Jul 2011, 11:52
What, did Dr. Suess have a hand in designing Java?a thunk is a function that takes no arguments.
The Force will be with you, Always.
-
Rob Cashwalker - Programmer
- Posts: 2167
- Joined: 09 Sep 2008, 15:09
- Location: New York
- Has thanked: 5 times
- Been thanked: 40 times
Re: making code wait on Input
by Braids » 08 Jul 2011, 13:45
.Rob Cashwalker wrote:What, did Dr. Suess have a hand in designing Java?a thunk is a function that takes no arguments.
.
if there's a funk in your thunk that's passed by reference,
and your lesser professor is demanding more deference,
then junk your thunk for a grander scheme;
and pass lambda on as an internet meme.
from http://dictionary.reference.com/browse/thunk under "Computing Dictionary":
In fact, according to the inventors, it was coined after they realised (in the wee hours after hours of discussion) that the type of an argument in ALGOL 60 could be figured out in advance with a little compile-time thought, simplifying the evaluation machinery. In other words, it had "already been thought of"; thus it was christened a "thunk", which is "the past tense of "think" at two in the morning".
"That is the dumbest thing I've ever seen." --Rob Cashwalker, regarding Innistrad double-sided cards. One of the first times he and I have ever agreed on something. 

-
Braids - Programmer
- Posts: 556
- Joined: 22 Jun 2011, 00:39
- Location: Unknown. Hobby: Driving myself and others to constructive madness.
- Has thanked: 1 time
- Been thanked: 1 time
Re: making code wait on Input
by friarsol » 09 Jul 2011, 15:00
Did you get anywhere with this Slap? Looks like here's another issue we have with it: http://code.google.com/p/cardforge/issu ... 1310223583
- friarsol
- Global Moderator
- Posts: 7593
- Joined: 15 May 2010, 04:20
- Has thanked: 243 times
- Been thanked: 965 times
Re: making code wait on Input
by slapshot5 » 09 Jul 2011, 15:53
I tried a post-input command implementation, but the Input object I wanted didn't exist when I expected.friarsol wrote:Did you get anywhere with this Slap? Looks like here's another issue we have with it: http://code.google.com/p/cardforge/issu ... 1310223583
I ended up just coding around it for the card I wanted to add: Chains of Mephistopheles
-slapshot5
- slapshot5
- Programmer
- Posts: 1391
- Joined: 03 Jan 2010, 17:47
- Location: Mac OS X
- Has thanked: 25 times
- Been thanked: 68 times
11 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 32 guests