260 views
in Getting started by

Hi,

I'm not getting my head around how to pass information between instances of components, I read through the documents specific to that. I did also successfully use these practices from the document in other part of my project....But this specific situation, i'm stuck....

My project is a simple tic-tac-toe game. 

In my project I have a unit called Game, that has

  • a GameField GUI Class Component. 
  • a FieldItem GUI Class Component
  • a Player Data Class Component

The GameField has 9 instances of FieldItem and 2 of player. Now I want to pass a property from 1 player instance to 1 FieldItem instance. I need the property to correctly display something in the FieldItem instance.

I tried to access the information of player instance inside the FieldItem instance via a slot method. This method is invoked through an SimpleTouchHandler. things I tried was to make a reference with the ^operator. But also tried to access it through an invalid syntax like "game::GameField.property"

 

Kind regards,

Xiu

1 Answer

0 votes
by

Hello Xiu,

Now I want to pass a property from 1 player instance to 1 FieldItem instance. 

If I understood your application case correctly, you have two objects: Player and FieldItem and you want to assign to the FieldItem a value from the Player object. Assuming the corresponding values are stored as properties in the Player and the FieldItem class, the following code could be adequate:

FieldItemObject.SomeProperty = PlayerObject.SomeProperty;

Each time the above code is executed, the actual value of the property from the PlayerObject is assigned (copied) to the FieldItemObject. This expects that the code is execute just in the momenent when you want the value to be transferred. Is this what you are trying to achieve?

Other approach would be to connect PlayerObject with  the FieldItemObject. In this case, the FieldItemObject would store a reference to a property existing in the PlayerObject. Consequently, the FieldItemObject can access (read or modify) the referenced property 'remotely' whenever it is required. This approach expects that the property in the FieldItem class is declared to be able to store a reference to another property. For example, if you want to store in the property a reference to an int32 property, the property has to be declared with type ^int32 - note the leading ^ sign. Then you can store a reference to an int32 property inside this property:

FieldItemObject.SomeProperty = ^PlayerObject.SomeProperty;

The implementation in the FieldItem class can thereupon read and modify the referenced property. Please note again the usage of the ^ sign. It de-references the reference resulting in an access to the property:

// Inside FieldItem class

// Modify the referenced property
SomeProperty^ = 1234;

[...]

// Use the referenced property
DoSomething( SomeProperty^ );

I hope it helps you further. See also the chapter Implementing component interface.

Best regards

Paul Banach

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...