Create a dynamic picture in JSX using Struct parameters? - html

I am creating a cryptoKitties Dapp and want to create a dynamic picture based on my Struct parameters. When a kitty is breeded or minted I create a Struct with random features of the kitty, like hair color, eye color, gender etc. In my table I want to add a dynamic picture of each kitty based on these parameters.
I mostly write in solidity, do truffle tests and write some frontend, so Im not really savvy in this area or JSX, so any example based on my code would be great :) I was trying something with canvas but got only errors.

Related

Unreal Engine Acces Variable From Different BP Actor

I am currently trying to simulate a solar system in unreal engine using blueprints. In order to calculate the force with which the actor (eg moon) should move, I need to know the mass of the parent actor (eg earth).
I am having issues trying to achieve this though, since I am quite new to Unreal. When I run my script, I am getting an error:
Blueprint Runtime Error: "Accessed None trying to read Class from property CallFunc_GetObjectClass_ReturnValue"
with a reference to Set ParentMass
which has to do with the following BP setup:
I am pretty sure this is happening because I am trying to retreive the mass of the parent but im doing it the wrong way.
Could anyone help me with retreiving the 'mass' value of the parent object?
Thanks!
What you're looking for is just the object reference to the parent planet, not it's class.
In your moon blueprint, make a variable called ParentPlanet of type BP_Earth object reference (or whatever the name of your earth BP is).
Click the eyeball beside the new variable to make it instance editable
Back in the main viewport, click on your moon in the world outliner. You should now see an option in the details panel to select the parent planet.
In BP_Moon, on begin play you can now get the parent reference, get it's mesh component, and use the node GetMass to find the mass of the mesh.

Data driven game with phaser 3

well i'm working on an e-learning platform for kids that contain courses and each course contain lessons and some games
games will be programmed in phaser 3
so the admin in the dashboard will have a form to add new course (add the lesson which is a video and also a link to the phaser game since the admin is not a developer so i wanted to transform my phaser game to a link or something like that )
my question is how to get a game set up to use data from json objects from a URL [sort of Data-driven game ]
ps: to develop this platform i'm using spring boot and angular
Until you actually instantiate a Phaser game as e.g. const game = Phaser.Game(myconfig), you can do any number of things to load the required data asynchronously. So the part about getting data is resolved that way.
The question of how to actually use the data is a more broad question. I would consider thinking about the asset loading and then instantiation together, and set up predefined factory functions to consume the same data the Loader functions will take.
You can trivially load assets from json data with the pack method in the Loader plugin, see here.
Then, you need to implement something that will act upon those assets once they are loaded, depending on the data:
{
...
"sceneSprites":{
"oneSprite":{'
"textureKey": "myAssetLoaded",
"x":32,
"y":42,
"tint": 0xff0000
(etc)
}
}
}
The keys that you define in the "pack" part of the json will be in the TextureManager, and you just match that key in the object data.
Then you create a scene with a series of functions that iterate over the data you have and create objects based on the data:
class MyScene extends Phaser.Scene {
create(){
for(const obj of spriteData){
const spr=this.add.sprite(obj.x,obj.y,obj.texturKey)
spr.setTint(obj.tint)
}
}
}
This is just a rough sketch of the things you would have to do. In general you can create one phaser "game" that is built with enough helper factory functions ontop of what phaser provides, to consume the specific data you have in any of your given json files.
I am sure you could cover a lot of Phaser functionality this way, including tweens, shaders, and audio.

How to use JSON Utility to Import Data from Browser to Unity?

I am just getting started programming and I couldn’t wrap my head around the following problem I currently have:
I have a PHP Script which retrieves the CPU Temperature of a Raspberry Pi and shows it on a local Network in my browser. The output in my browser is just a blank page with the value e.g. 56.7 only and no more.
What I would like to know now is, if it’s possible with JSON Utility to take this value and import it into Unity -> to be more specific, into an Augmented Reality Environment using Vuforia, even if it’s on a local Network and the only output is just the temperature value.
Is there anyone who could answer these (probably trivial) questions and eventually could show me how the code could look like?
And is it correct to assume, that the value within Unity would change as soon as the value in my browser changes?
I would like to thank everyone in advance for any help at all and even though these questions seem obvious for experienced programmers, I wasn’t able to find a correct answer by now.
Best regards!
Use UnityWebRequest to contact your Raspberry Pi.
Parse the DownloadHandler.text any way you like. JSON Utility is one option for parsing the result, but it might be overkill if this is a hobby project that just gets one sensor value.
https://docs.unity3d.com/Manual/UnityWebRequest-RetrievingTextBinaryData.html
To parse the json with JsonUtility, you would make a class to hold the data, making sure to mark it with Serializable attribute.
[System.Serializable]
public class MyData
{
public float temperature;
}
And then parse it like this, in the RetrievingTextBinaryData example
MyData myData = JsonUtility.FromJson<MyData>(www.downloadHandler.text)
Assuming your JSON looks like this
{ "temperature":30.7 }
Note: to make it continuously poll your Raspberry Pi for updates, you would need to download the temperature in the Update() method instead of Start() like in the example code.

The best solution for background application logic?

I have 2 different types components. They both only use and contain an HTML5-canvas element, but need to show different types of data on a chart:
Component A (Only ever 1 of these)
Component B (0 to 4 of these)
Both components need the dateTime of the first data-entry from the two data-sets, but the dateTime of the last entry comes from their own respective data-sets.
Component A needs its first entry date from Component B.
Currently I do it like this:
Component B has the method that finds the date-limits from its own dataset. Using an Observer-pattern & Subjects, I broadcasts the returned dates through a service and into Component A.
The problem with this though, is that coupling suddenly becomes pretty tight. I can't initialize component A first, because it needs B to do its calculation first. Both components ideally should initialize and show/share their data simultaneously, and continue to do so. (E.g. If a user scrolls in one chart it should scroll all other components too, and so on.)
This is why I wanted an extra layer added on top of these components. A controller if you will.
I can't figure out what's best though:
A shared service that can take external data as input?
A container component? (Transclusion)
Another component, Component C, that A & B are children of?
As I'm still new to Angular 2, it's hard to tell which approach is best for future maintenance/development?
I'm being drawn towards creating another normal component as a parent, and have this component send and receive data to/from its children (A & B) as necessary.
I'm also uncertain as to what's "best practice" and if you can just use a component like an empty 'logic shell'. I've tried reading here and there, and I've found a lot, but I can't seem to get an exact answer to my question. It'll take time before I can comprehend all this knowledge and answer it myself, so I'm hoping someone could give me a helping nudge, thanks.
PS: I should add that my angular application will be a child-component in larger application, and will get its data from some other parent comp.
Why don't you put your logic into services?
You can also set up service hierarchies by injecting sub-services into a parent service.
If your logic is not UI / interaction related, you should put it into reusable services. If your logic is UI related, you could set up a parent component acting as a mediator between A and B (acting on their respective input/output parameters)
Whatever you do, it is a good idea to keep concerns separate.
Both A and B should not need to care about other components needing their output. Angular has Input/Output parameters for that.
Don't put some generic datetime calculation stuff into components. Make it reusable through services.
Keep coupling loose by introducing interfaces and injections.
Update:
Services should only use injectable constructor parameters, so you should pass your input using methods (or setters, but that is less expressive).
To pass arbitrary JSON objects, you could utilize any parameters. However if your json follows a certain structure, you could define an interface.
public doStuff(input: any): any { }
or
interface IMyDataContract {
dateField: string;
}
public doStuff(input: IMyDataContract): any { }

How to have variables accessible across keyframes- AS3

I'm working on a portfolio suggestion application in Flash, which consists of two views: ask user for 3 to 4 points of information, and display recommendations based on that information.
The first view is going swimmingly, as all I need are the graphics to be created. However, I'm having trouble understanding how a AS3 variable can be seen across keyframes when it was declared and initialized on the first frame.
The only multi-view app I've done is a Restaurant Guide flash app that was described in Adobe Flash CS5 Classroom in a Book. In that example, the only AS function on four of the views
was a stop() function.
If I were to do the same in this app, and declare the variables as global in the first frame, will they be accessible throughout?
CLARIFICATION
Two comments have said that my question is unclear, so I hope this makes my question more understandable. I want to know how, if I gather all the user information on Frame 1 and then switch to a view on Frame 15, to access those variables on Frame 1.
This isn't really the way you're supposed to work in AS3. Each view should be an object in your library with an associated class. Your document should also have a class associated with it, and it is here that you would hold your common data. The document class would instantiate each view as it is required and pass in the relevant variables.
That said, if you want to work the old way you shouldn't have trouble declaring a variable on frame 1 like this:
var myVar:String = "Hello!";
and then accessing it on frame 15 of the same timeline like this:
trace(myVar);
If that's what you're doing and it's not working then you'll need to update your question with some code examples.