Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,086 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Problems with pointers inside actions #459148
04/25/16 03:00
04/25/16 03:00
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline OP
Newbie
Florastamine  Offline OP
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
I've created a simple action which displays an arbitrary text whenever the player comes close to the entity, and the string to be displayed is defined in string1. The problem is, whenever I assign the action to 2 or more entities in the level, when displaying the text, it appears to display both the old and the new content, overwriting each other. The action's code has some local pointers initialization at the header, like this:
Code:
action act_notepad()
{
    TEXT *my_text = txt_create(1, 1);
    ...
    // When the player comes close to the text, display it.
    // Hides the text if the distance between the player and me is larger than 242.0.
    // Destroys the text if the level is no longer valid.
}



Here are a few screenshots to make it clearer what I mean. I have two entities in the level, they share the same action, with different string1 on each entity:

First time, the text just do the correct thing:


But when viewing the second text, the problem emerges:


I know the problem lies somewhere in the local TEXT object inside the action definition, but I don't have a solid reason as well as how to solve this as I have no idea how "action" works and how these local objects are stored in Acknex.

Have anybody encountered something like this before? Any insights is appreciated.

Re: Problems with pointers inside actions [Re: Florastamine] #459153
04/25/16 05:34
04/25/16 05:34
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
I guess having an insight at the actual code would be better in order to help you, instead of just speculating around.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: Problems with pointers inside actions [Re: alibaba] #459154
04/25/16 06:40
04/25/16 06:40
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline OP
Newbie
Florastamine  Offline OP
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
Thanks, I've tried dumbing down the project to the point that it only contains the relevant code in order to re-produce the issue, but so far no luck, the problem is still there. I can upload the project here if you want to take a look.

Re: Problems with pointers inside actions [Re: Florastamine] #459155
04/25/16 07:53
04/25/16 07:53
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline OP
Newbie
Florastamine  Offline OP
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
Here's the oversimplified project which only contains some basic code to get the game up and working. The faulty code is located in ./source/game/ai/behavior_static.c Press [0] to unlock the camera and move around. You can see that both the old and the new text objects overwriting each other, although I've hid them in the else {} branch in the code.

https://dl.dropboxusercontent.com/u/26857618/DPFL2.rar

Re: Problems with pointers inside actions [Re: Florastamine] #459157
04/25/16 10:15
04/25/16 10:15
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
I took a quick look at the code (I have not 3DGS here right now), but in order to use the "hit"-Struct, you need to set the flag "SCAN_TEXTURE". Try it out. I'll take a second look when I'm back home.


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
Re: Problems with pointers inside actions [Re: alibaba] #459159
04/25/16 12:08
04/25/16 12:08
Joined: Apr 2015
Posts: 20
Vietnam
F
Florastamine Offline OP
Newbie
Florastamine  Offline OP
Newbie
F

Joined: Apr 2015
Posts: 20
Vietnam
As far as I know, setting SCAN_TEXTURE only fills the hit struct with texture information. The struct itself can still be used (only texture information is unavailable). In my code I only use hit->entity, which points to the target entity.

Re: Problems with pointers inside actions [Re: Florastamine] #459162
04/25/16 13:41
04/25/16 13:41
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Did not quite read everything but...
I usually only have one global dummy TEXT. When I want to render text, for instance for individual signs, dialog with NPCs and so on, I copy the string(s) to that TEXT object and use draw_obj(...) to draw it.
IMO that's a much cleaner approach as you don't have to manage text creation, delete and set/ reset the SHOW flag (for example on level change).


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Problems with pointers inside actions [Re: Superku] #459166
04/25/16 14:24
04/25/16 14:24
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
>>TEXT *my_text = txt_create(1, 1);<<

The problem is that this creates a text any time you call that function, and thus will quickly overwhelm your game with lots of TEXTs. I don't know if this is the reason of your problem, but the proper way to create something in a more-than-once called function is:

static TEXT *my_text = NULL;
if(!my_text) my_text = txt_create(...);

Objects that are global to the whole game, such as a TEXT object, should be normally created in the main function and not in a local action.

Re: Problems with pointers inside actions [Re: jcl] #459174
04/25/16 20:52
04/25/16 20:52
Joined: Sep 2003
Posts: 9,859
F
FBL Offline
Senior Expert
FBL  Offline
Senior Expert
F

Joined: Sep 2003
Posts: 9,859
...or make sure to use ptr_remove() on the TEXT* when hiding it again.

Re: Problems with pointers inside actions [Re: FBL] #459176
04/26/16 06:05
04/26/16 06:05
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
I am sure both notes are inside 'my->distance' range and 'ent_get_type(hit->entity) == STATIC_NOTEPAD' gets true no matter wich note camera is looking to, so both texts are shown.

Modifying that comparision to 'hit->entity == me' will solve the problem since you know 'me' is a note already.

Anyway your code performs a c_trace for each note. That is a pretty wasteful way to go. Try to call a single 'c_trace' for every scaneable entity just after camera movement inside cameras function. The use of 'c_ignore' is a good habit too.

Salud!


Moderated by  old_bill, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1