• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

How to remove object?

Podge

Member
Joined
Nov 10, 2019
Messages
61
In this example code I am creating some cards both red and black.
For the life of me I cannot figure out how to remove, lets say all red cards or all black cards.

I've mucked around with things like RemoveFirst and RemoveEach, with no luck at all. Can anyone help me with this?

Strict
Import mojo

Global card_count:Int

Class Game Extends App

Field cards := New Stack<Card>'all cards

Method OnCreate:Int()
SetUpdateRate(60)
For card_count = 0 Until 10'85'create all cards
cards.Push New Card
Next

Return 0
End Method

Method OnUpdate:Int()
Return 0
End Method

Method OnRender:Int()
Cls()
Local y:Int = 0
For Local card := Eachin cards'cycle through all cards
DrawText(card.name, 0, y)
y = y + 10
Next

Return 0
End Method

End

Class Card'class for all cards

Field name:String'name
Method New()'create full deck, 84 cards
If card_count >= 0 And card_count <= 5
name = "Red"
End
If card_count > 4
name = "Black"
End
End Method'end method - New Card

End Class'class card

Function Main:Int()
New Game()
Return 0
End
 
Please use code blocks for pasting code (insert, code). Makes it easier to read and doesn't mess up indentation.

Anyways: Stack.RemoveFirst etc. expect a value of type T - in your case T is Card. So you have to pass it the exact card you want to remove, e.g:
Cerberus:
For card := Eachin cards
    ' this card is named red
    If card.name = "Red" Then
        ' remove its first occurence in cards
        cards.RemoveFirst(card)
    Endif
Next
 
Hello Holzchopf,

That's it, thanks a lot for that, you have no idea how long I spent trying to figure this out.
I really appreciate the help and I'll be sure to use indentation next time. God knows my code is hard to read at the best of time.

Thanks again,

Take care.
 
And this:

1594922061964.png
 
It is no IDE but this forum. When you post code, look at the icons above the text area.
 
Back
Top Bottom