I am new to Adobe Flash Action Script 3.0 but learning.
Geweer = the guy you are and kogel = bullet
I am having this code:
var geweer; .
stage.addEventListener(KeyboardEvent.KEY_DOWN,beweeg);
function beweeg(event:KeyboardEvent)
{
switch(event.keyCode)
{
case 38:
geweer.y = geweer.y -10;
kogel.y = kogel.y -10;
break;
case 40:
geweer.y = geweer.y +10;
kogel.y = kogel.y +10;
break;
case 32:
kogel.x = kogel.x +20;
break;
}
}
As you see. Case 32. When launched. The bullet will move from position only once(unless I press it multiple times). How can i make it to repeat(Without pressing multiple times)? And do it multiple times, to shoot multiple bullets.
You will have to write a game loop which handles all your logic at a regular time interval. A basic way to do this in actionscript is by subscribing to the ENTER_FRAME event.
Since your programming skills seem limited I suggest you first try to follow several tutorials on the subject you are attempting to program before asking such specific questions here.
A quick search seems to be able to help you. Check out 'PART 2 - Advanced detection' on this page.
Related
This code is for a modding engine, Unitale base on Unity Written in Lua
So I am trying to use a Boolean Variable in my script poseur.lua, so when certain conditions are met so I can pass it to the other script encounter.lua, where a engine Predefined functions is being uses to make actions happens base on the occurring moment.
I tried to read the engine documentation multiple times, follow the exact syntax of Lua's fonction like GetVar(), SetVar(), SetGobal(),GetGlobal().
Searching and google thing about the Language, post on the subreddit and Game Exchange and tried to solve it by myself for hours... I just can't do it and I can't understand why ?
I will show parts of my codes for each.
poseur:
-- A basic monster script skeleton you can copy and modify for your own creations.
comments = {"Smells like the work\rof an enemy stand.",
"Nidhogg_Warrior is posing like his\rlife depends on it.",
"Nidhogg_Warrior's limbs shouldn't\rbe moving in this way."}
commands = {"GREET", "JUMP", "FLIRT", "CRINGE"}
EndDialougue = {" ! ! !","ouiii"}
sprite = "poseur" --Always PNG. Extension is added automatically.
name = "Nidhogg_Warrior"
hp = 99
atk = 1
def = 1
check = "The Nidhogg_Warrior is\rsearching for the Nidhogg"
dialogbubble = "rightlarge" -- See documentation for what bubbles you have available.
canspare = false
cancheck = true
GreetCounter = 5
Berserk = false
encounter:
-- A basic encounter script skeleton you can copy and modify for your own creations.
encountertext = "Nidhogg_Warrior is\rrunning frantically"
nextwaves = {"bullettest_chaserorb"}
wavetimer = 5.0
arenasize = {155, 130}
music = "musAncientGuardian"
enemies = {"poseur"}
require("Monsters.poseur")
enemypositions = {{0, 0}}
-- A custom list with attacks to choose from.
-- Actual selection happens in EnemyDialogueEnding().
-- Put here in case you want to use it.
possible_attacks = {"bullettest_bouncy", "bullettest_chaserorb", "bullettest_touhou"}
function EncounterStarting()
-- If you want to change the game state immediately, this is the place.
Player.lv = 20
Player.hp = 99
Player.name = "Teemies"
poseur.GetVar("Berserk")
end
Thank you for reading.
The answer to my problem was to use SetGobal(), GetGobal().
For some reasons my previous attempt to simply use SetGobal()Resulted in nil value despite writing it like that SetGobal("Berserk",true) gave me a nill value error, as soon as I launch the game.
But I still used them wrong. First I needed to put it SetGobal() at the end of the condition instead of at the start of the the poseur.lua script because the change of value... for some reasons was being overwritten by it first installment.
And to test the variable in the function in my encounter.lua, I needed to write it like that
function EnemyDialogueStarting()
-- Good location for setting monster dialogue depending on how the battle is going.
if GetGlobal("Jimmies") == true then
TEEEST()
end
end
Also any tips an suggestions are still welcome !
Well firstly, in lua simple values like bool and number are copied on assignment:
global={}
a=2
global.a=a--this is a copy
a=4--this change won't affect value in table
print(global.a)--2
print(a)--4
Secondly,
SetGobal and the other mentioned functions are not part of lua language, they must be related to your engine. Probably, they use word 'Global' not as lua 'global' but in a sense defined by engine.
Depending on the engine specifics these functions might as well do a deep copy of any variable they're given (or might as well not work with complicated objects).
I have a project where I am trying to use multiple components in an ActionScript. I have a numeric stepper and text input and a couple buttons. The trouble is the events they dispatch in these components are similar (eg the "click" event), and I am getting a mishmash of scope problems trying to handle this. What I did was create a function in my .as file that had a switch statement to catch multiple "click" events, but for some reason the numeric stepper still is not playing well with the others and keeps setting the instance value to "undefined", probably because there is a scope issue.
Anyway here is a portion of the code that I think is where there is trouble.
(vars: plus_Btn and minus_Btn are button objects, they increment/decrement a private variable by adding or subtracting the value on the numeric stepper which is called stepSize_NS.)
stepSize_NS.addEventListener("click", this);
plus_Btn.addEventListener("click", this);
minus_Btn.addEventListener("click", this);
function click(evt:Object):Void{
switch (evt.target){
case minus_Btn:
command -= stepSize_NS.value;
break;
case plus_Btn:
command += stepSize_NS.value;
break;
case stepSize_NS:
trace("Step Size changed to " + stepSize_NS.value);
//eventually this will do something else whenever the stepper chngs
break;
default:
break;
}//end switch
}//end function
I am having a lot of headache trying to make a game loop in Actionscript. Searched a lot and could not to find the answer. My idea is:
When de game starts, it defined the units sequence of attack, based in their speed (each player can have until 8 units, of any kind). I store this sequence into an Array. I did create the engine in Javascript returning the values in console.log... and works fine... but transporting it to AS3, the things aren't working as I thought.
So... I have the sequence... and now I do the loop
This is my logic (not using any specific language):
for (i = 0; i < sequence.length; i++) {
isHitting = sequence[i]; // first unit from list is the hitter
isDefending = mostPowerfulEnemy(); // method to check who will be attacked
// here is the problem!!!!
isHitting.moveTo(isDefending); // method to move the MC near the target
var kills = isHitting.hit(isDefending); // calc the damage and return the kills
if (isDefending.amount <= 0) {
// remove the MC from Stage and the sequence list
continue; //to move to the next hitter in sequence
} else {
isDefending.amount -= kills;
continue; //to move to the next hitter in sequence
}
}
The problem is: all units are moving at same time!
I've learning about Events and the method addEventListener() sounds like the best option, but i have to call a function, right? I do it... so the unit move to the point... hit... and stop... I need a way to say: "hey, this unit already did his move, did stop and did hit the target, you can now continue the loop" (since I cant return a continue, ofc)
This is what I want:
Some suggestion?
Sorry my bad english.
Always feel like I'm making something far more complicated than it has to be. I'm currently playing around with the WoW addon, Tongues, in hope of make a custom dialect filter - which is quite easy of course, very noob-friendly. At this point, there is one thing I want to accomplish-- something of which feels to have the implications far beyond this -- that is just novelty, but before I give up completely (lots of hours trying different things with no headway) I was hoping someone could come by, get a cheap laugh and perhaps help me fix this if they understand my point. And who knows, posting this new helpless questions might bump me up to being able to finally upvote!
Tongues.Affect["Drunk"] = {
["substitute"] = {
[1] = merge({
{ ["([%a]+)(%A*)$"] = "%1 ...hic!"},
Tongues.Affect["Slur"]["substitute"][1]
});
};
["frequency"] = 100;
};
What this does is simply add on the "...hic!" to sendchatmessage(); I believe it is. The frequency part seems completely broken and only the GUI slider in the game matters for that. What I was hoping to accomplish was to repurpose this and make the "...hic!" an actual randomized word. Since the mod itself handles the chance that it happens, I figured all that is needed left is to replace the string with a function=X. It's, of course, intensely way over my head, but despite checking the Lua of several mods, nothing feels like "it will fit."
The best I could come up with,
Tongues.Affect["TESTAFFECT"] = {
["substitute"] = {
[1] = merge({
{ ["([%a]+)(%A*)$"] = function(b)
local rand = Math.Random(1,2)
if (rand == 1) then
b = "test1"
return b
elseif (rand == 2) then
b = "test2"
return b
end
end
Leaves a gloriously useless message in the error mod BugSack - of course my attempt is wrong, but there's no way to know how!
I'm assuming this is enough information - as I said, very user friendly mod without any need to understand how it really works (Although I'd love to ready study it after this "project")
Anyone? Regardless, thank you for your time in simply even reading this far.
Update: Downvotes, okay! That's cool too. A little unpredictable, but sure. The error is as follows
15x Tongues\Core\dialects.lua:172: attempt to index field 'Affect' (a nil value)
Tongues\Core\dialects.lua:172: in main chunk
Locals:
175 in dialects.lua is
Tongues.Affect["Wordcut"]["substitute"][1],
Which has nothing to do with what I'm trying to accomplish, and works just fine.
Sorry that my question was an inconvenience. I asked to the best of my ability and the best of my ability to articulate the question proved to be less then stellar. The example codes I had provided were the only way I could articulate showing what I was trying to do.
I was misinterpreting the error frame and discovered that behind the useless stack that calls an error where there is, in fact, none, is a stack that calls the error in syntax at the time that broke it.
I'm sharing my results, regardless if the community finds this useless. I learned a tremendous amount from this personally, which is the only incentive in that I asked for help.
Tongues.Affect["TEST"] = {
["substitute"] = {
[1] = {
["([%a]+)"] = function(a)
return a
end;
["(%A*)$"] = function(a,b)
local rand = math.random(1,2)
if (rand == 1) then
b = "test1"
return b
end;
if (rand == 2) then
b = "test2"
return b
end;
end;
};
};
};
Hope it helps someone out there - as expected, I made it more complicated than it had to be. Simply "jiggling" the symbols is all that was needed.
First, apologies as I realize this is only tangentially related to parser programming.
I've spend hours looking for a text file containing something like the following but with hundreds (hopefully thousands) of sub-entries. A complete biological classification file would be perfect. A massive version of the following would be great as my parser parses simple tabbed files:
TL,DR - I need a massive single-file hierarchical data set something like the following:
Kindoms
Monera
Protista
Fungi
Plants
Animals
Porifera
Sponges
Coelenterates
Hydra
Coral
Jellyfish
Platyhelminthes
Flatworms
Flukes
Nematodes
Roundworms
Tapeworms
Chordates
Urochordataes
Cephalochordates
Vertebrates
Fish
Amphibians
Reptiles
Birds
Mammals
The best I've been able to find are tree-of-life images (from which I transcribed the sample data set above). A single file with a TON of real data would be awesome. It doesn't have to be a biological classification data set, but I would really like the data to reflect something in the real-world. (My parser feeds a menu - would be great if the remainder of my testing was with a data set that actually meant something!) Even if the file is not tabbed but the data was fairly easily regex'ed to a tabbed format... that would be great.
Any ideas? Thanks!
It is possible that the xml layout was changed since the last answer but the code submitted above is no longer accurate. The resulting dump is extraneous. Some of the nodes have aliases (denoted as 'othername') that are reported as distinct nodes themselves.
I used the script below to generate the correct dump.
<?php
$reader = new XMLReader();
$reader->open('http://tolweb.org/onlinecontributors/app?service=external&page=xml/TreeStructureService&node_id=1'); //15963 is the primates index
$set=-1;
while ($reader->read()) {
switch ($reader->nodeType) {
case (XMLREADER::ELEMENT):
if ($reader->name == "OTHERNAMES"){
$set=1;
}
if ($reader->name == "NODES"){
$set=-1;
}
if ($reader->name == "NODE"){
$set=-1;
}
if ($reader->name == "NAME" AND $set == -1){
echo str_repeat("\t", $reader->depth - 2); //repeat tabs for depth
$node = $reader->expand();
echo $node->textContent . "\n";
}
break;
}
}
?>
This turned out to be such a pain in the ass. I finally tracked down a data feed from "The Tree of Life Web Project" at tolweb.org. I made the php script below to provide the basic functionality my post was looking for.
Change the node_id to have it print a tabbed representation of any of tolweb.org's data - just take the id from the page you're browsing on their site and change the node_id below.
Be aware though - their data feeds serve up large files, so definitely download the file to your own server (and change the "open" method below to point to the local file) if you're going to hit it more than once or twice.
More info on tolweb.org data feeds can be found here:
http://tolweb.org/tree/home.pages/downloadtree.html
<?php
$reader = new XMLReader();
$reader->open('http://tolweb.org/onlinecontributors/app?service=external&page=xml/TreeStructureService&node_id=15963'); //15963 is the primates index
while ($reader->read()) {
switch ($reader->nodeType) {
case (XMLREADER::ELEMENT):
if ($reader->name == "NAME"){
echo str_repeat("\t", $reader->depth - 2); //repeat tabs for depth
$node = $reader->expand();
echo $node->textContent . "\n";
}
break;
}
}
?>