Trying to make a random sprite clickable - phaser-framework

I would like to ask the gurus of stackoverflow as I know that most of the time I find my answers here, and I want to thank the community for all the vast information on this site, Im a bit stuck on a small little learning projeck I got going and any assistance would be greatly appreciated, this is my code below (I will explain the issue below the code):
this.load.atlas('enemies', 'enemies.png','enemies.json'); ####This goes on preload function
#####everything below I added to create function
var monsterData = [
{name: 'Aerocephal', image: 'aerocephal'},
{name: 'Arcana Drake', image: 'arcana_drake'},
{name: 'Aurum Drakueli', image: 'aurum-drakueli'},
{name: 'Bat', image: 'bat'},
{name: 'Daemarbora', image: 'daemarbora'},
{name: 'Deceleon', image: 'deceleon'},
{name: 'Demonic Essence', image: 'demonic_essence'},
{name: 'Dune Crawler', image: 'dune_crawler'},
{name: 'Green Slime', image: 'green_slime'},
{name: 'Nagaruda', image: 'nagaruda'},
{name: 'Rat', image: 'rat'},
{name: 'Scorpion', image: 'scorpion'},
{name: 'Skeleton', image: 'skeleton'},
{name: 'Snake', image: 'snake'},
{name: 'Spider', image: 'spider'},
{name: 'Stygian Lizard', image: 'stygian_lizard'}
];
var monsters = this.add.group();
var monster;
let currentmonster = Phaser.Utils.Array.GetRandom(monsterData);
monsterData.forEach(function(data) {
monster = monsters.create(400,300, 'enemies', currentmonster.image).setOrigin(0.5);
monster.details = data;
});
monster.on('pointerdown', function (pointer) {
this.setTint(0xff0000);
});
monster.on('pointerout', function (pointer) {
this.clearTint();
});
monster.on('pointerup', function (pointer) {
this.clearTint();
});
Basically my monsters do spawn as expected and they do change sprite every time I refresh the page, but the click function does not works, it simply wont click on it, and nothing happens, no errors on console nothing, am I approaching this incorrectly? please any suggestion is greatly appreciated.
my main functions look like the ones on this tutorial: Tutorial

You're missing the setInteractive() method that lets Phaser know a gameobject should listen for input events.
Modify this line:
monster = monsters.create(400,300, 'enemies', currentmonster.image).setOrigin(0.5);
To look like this instead:
monster = monsters.create(400,300, 'enemies', currentmonster.image).setOrigin(0.5).setInteractive();
You can read more about setInteractive in the Phaser 3 Docs for Sprite.

Related

How to do Autocomplete text suggestion in message box in BOT

I created a BOT with LUIS and node.js and also published in Skype Channel.
Now I wants to add Autocomplete text suggestion in message box.
Am unable to find documentation for node.js
Please assist me.
Autcomplete can be accomplished with a few different NPM packages. Here's one as an example that looks not too bad to implement: https://www.npmjs.com/package/autocompleter
Code example:
var countries = [
{ label: 'United Kingdom', value: 'UK' },
{ label: 'United States', value: 'US' }
];
autocomplete({
input: document.getElementById("country"),
fetch: function(text, update) {
text = text.toLowerCase();
// you can also use AJAX requests instead of preloaded data
var suggestions = countries.filter(n => n.label.toLowerCase().startsWith(text))
update(suggestions);
},
onSelect: function(item) {
alert(item.value); // will display 'US' or 'UK'
}
});
You'll obviously have to adapt this to your needs and exact use case, but should be easy enough to implement.

How do use Google Actions client library version 2 to create a dynamic list using forEach or any other iterator in Node

I am building using Node Google Actions client library version 2 to create a dynamic list using forEach or any other iterator in Node. Before I plough on does addList work with version 2 and if so does anyone have an example.
Hope someone can help but if not will do it myself and post up.
ditto for Carousel BTW but that should be very similar
Here is an example:
let items = {};
let array = ['first', 'second', 'third'];
array.forEach(element => {
items[element] = {
title: element,
image: new Image({
url: "url",
alt: "alt image title"
})
)}
})
conv.ask("List")
conv.ask(new List({
title: 'List',
items: items
)};

gridx shows the last record of my dynamic data

hello am using grid to display dynamic data dojo, but what I get is that sample (n) times, but always shows me the last record, but if I do it with dummy data works well, I hope you help me with this issue.
define(["js/module/modControllerPersona", "dojo/store/Memory", "gridx/Grid", "gridx/core/model/cache/Sync", "dojo/data/ObjectStore"],
function(modControllerPersona, Store, Grid, Cache, ObjectStore){
var grid, store, data;
var persona = new Array();
return{
datagridx: function(){
modControllerPersona.persona().then(function(result){
persona = JSON.parse(result);
data = persona.items;
store = new Store({data: data});
var columns = [
{name: 'id', field: 'descripcion'},
{name: 'descripcion', field: 'id_Maquinaria'},
{name: 'descripcion', field: 'id_tipo_Maquinaria'},
{name: 'Nombre', field: 'kind'},
{name: 'Nombre', field: 'nombre'},
{name: 'Nombre', field: 'visible'}
];
grid = new Grid({
cacheClass: Cache,
store: store,
structure:columns
}, 'gridNode');
grid.startup();
});
Perhaps this can help you, I had a similar problem. If you don't have a column id it doesn't work right. But if you adjust your store to something like this:
var store = new Memory({
data: data,
idProperty: 'descripcion'
});
Perhaps the "new Memory" is not necassary. In my case this works (but I didn't tested it here again). I have no id but I have another unique field instead of this. I suppose it is because of your
{name: 'id', field: 'descripcion'}
If you use instead of "descripcion" the name "id" I think it should work too.
Just add "idProperty" for Gridx, I solved my problem
My dynamic data:
var data = [{"ID":"1","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code - Review Code","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"11.6","ITS":null},{"ID":"2","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code - Review Code - UT","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"4.6","ITS":null},{"ID":"3","Số liệu thống kê":"Năng suất lập trình","Ngôn ngữ LT":"Java Web","Công đoạn":"Code","Loại Project":"Customize/Full","Đơn vị tính":"KLOC/ManMonth","UCD1":"15.15","ITS":null}];
require([
'dojo/store/Memory',
'gridx/Grid',
'gridx/core/model/cache/Sync'
], function (Memory, Grid, Cache) {
var store = new Memory({
data: data,
idProperty: 'ID'
});
Hope this help

How to get value form nested object in mongoose?

I have some code on nodejs using mongoose module, and I need to get nested value, let I show you:
I create Schema
var clientScheme = mongoose.Schema({
name: Object
address: String,
number: Number,
operator: Object,
services: Object,
email: String
})
Then I create model:
var Client = mongoose.model('Client', clientScheme);
Then goes creating/saving - it's easy, I just show you first client.json
{
"name":{
"first":"John",
"last":"Smith"
},
"address":"Avenue 1",
"number": 7012341,
"email":"john#gmail.com"
}
And then, I need to get this client by first name. I try to:
clients.find({"name":{"first":"John"}})
Doesn't work.
What's wrong?
You can do this with :
db.clients.find({"name.first":"John"})
You should use dotted notation:
Client.find({"name.first": "John"}, function(err, clients){
// your callback body here
});
It doesn't work because you try to find a record which has 'name' exactly like this:
{first: "John"}
but your client has name: {first: "John", last: "Smith"}
So, any of the following queries will find your client:
clients.find({"name.first": "John"}) or
clients.find({"name.last": "Smith"}) or
clients.find({"name": {first: "John", last: "Smith"}})
Hope it helps.

CompoundJS: Populating database with seed file hangs

I'm trying to populate my CompoundJS application's Mongo database with seed files, but whenever I run compound seed, the terminal hangs after my console.log statements... the database fills, but I have to kill the command with Ctrl-c.
I've tried doing compound seed harvest, but that doesn't create proper seed files, so I've decided to make my own. Here is my respective code:
db/seeds/development/Host.js (seed file)
console.log("Seeding Hosts....");
var hosts = [
{
hid: '1',
name: 'MY API',
domain: 'mydomain.com'
}
];
hosts.forEach(function(obj, err){
Host.create(obj, function(err, host){
console.log('host Added: ', host);
});
});
db/schema.js
var Host = describe('Host', function () {
property('hid', String);
property('name', String);
property('domain', String);
set('restPath', pathTo.hosts);
});
config/database.js
module.exports = {
development: {
driver: 'mongodb',
url: 'mongodb://localhost/apicache-dev'
},
test: {
driver: 'mongodb',
url: 'mongodb://localhost/apicache-test'
},
production: {
driver: 'mongodb',
url: 'mongodb://localhost/apicache-production'
}
};
Like I said, when I run compound seed, it shows both console.log statements, and it puts my data into the database, but it just hangs... never actually returning to the command line, so I'm forced to kill it with Ctrl-c. I would like to solve this problem, as I have to automate this process, and it's a bit hard automating if it's just hanging. What am I doing wrong? Any help would be appreciated!
Cross-posted.
EDIT
So when I try to use the Coffee script version that's generated from compound seed harvest:
db/seeds/development/Host.coffee
Host.seed ->
hid: '1'
name: 'MY API'
domain: 'mydomain.com'
id: "52571edd2ac9056339000001"
I get the error collection name must be a String. So I was a little curious and went to where that error was being generated... in node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/collection.js on line 103. I put a console.log(collectionName) right before that if statement and saw an interesting output...
{ hid: '1',
name: 'MY API',
domain: 'mydomain.com',
id: NaN }
So clearly it's not a string, but a hash object, and my collection's name (Host) is nowhere in sight. Seems like a bug to me.
So I finally got it to work. Apparently, there was something wrong with the auto-genned id from the harvest command, so I ended up deleting that line, and voila! Planting the seeds works like a charm. I converted the rest of my JS files to Coffee script files and everything works. Sometimes you just need to have a conversation with yourself on the Internet...
Here's my seed file:
Host.seed ->
hid: '1'
name: 'MY API'
domain: 'mydomain.com'
And doing compound seed works without hanging and populates the database. Guess Coffee script is the way to go?

Resources