About Store Forum Documentation Contact



Post Reply 
Passing data between States [Workaround]
Author Message
JonathonA Offline
Member

Post: #1
Passing data between States [Workaround]
Hello there, and happy new year to you all! smile

Come across a problem; I have divided the character creation process into three States (by States I mean the Esenthel class: State).

The problem is this, can data be passed from one State to the next? I noticed that when you call <StateName>.set(...) there is no ability to pass any sort of user data.

Has anyone got a suggestion on how to get around this?

I have tried a static struct in a header file elsewhere in the code (for storing various bits of data about the character being created; on a bit of a tight deadline at the moment) but I noticed that if I set it in one State, then move on to the next State the data in that struct doesn't appear to persist so I wondered if that was a threading issue maybe since it isn't thread-safe? If I step back to the previous State the data appears to have persisted (either that or it is in the right scope at that particular point in time)

I did scan for any similar topics to this but didn't come across anything, apologies if there is already a similar topic.
(This post was last modified: 01-10-2012 11:52 PM by JonathonA.)
01-09-2012 08:34 PM
Visit this user's website Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #2
RE: Passing data between States
I may post a feature request for passing user data between State instances unless anyone disagrees?
01-10-2012 02:23 PM
Visit this user's website Find all posts by this user Quote this message in a reply
fatcoder Offline
Member

Post: #3
RE: Passing data between States
No need for a feature request. Your original idea of a static class was on the right track. My current project uses something like this without a problem.

ChrData.h
Code:
struct ChrData
{
   Str name;
   Flt height;
   etc...
} extern chrData;

ChrData.cpp
Code:
#include "stdafx.h"
#include "Main.h"

ChrData chrData;
01-10-2012 10:54 PM
Find all posts by this user Quote this message in a reply
JonathonA Offline
Member

Post: #4
RE: Passing data between States
Hey fatcoder thanks for the response! Just finished trying something out very similar to what you have presented and it does work; glad to see someone else that has had to do something similar smile

Once I declared it extern I had no problems, still, surely having a means of passing user data between States through method calls would be worthwhile?
01-10-2012 11:51 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply