actionscript 2 go to another screen after variable = 10 - actionscript

I'm making a game where i have a character moving through a maze collecting coins. Once I have collected 10 coins i want my game to automatically go to the end keyframe. The variable Coincounter keeps a record of the number of coins the user has collected so far. So far i have this code to make my game do that....
if (_root.Coincounter == 10) {
trace("got to ten" +_root.Coincounter);
gotoAndStop(4) ;
}
The code is inside an onClipEvent - either keyDown or enterFrame, i can put it in either of them. The trace works fine so it's my gotoAndStop code that doesn't work - i'm not sure why. Thanks for the help.

Related

WoW Addon Help - Unit Reaction of MouseOver

I last created Mods back before Cataclysm. It's been a long time. Just now getting back into it. I'm just trying to write a very basic mod that cancels attacking with the right mouse button.
WorldFrame:HookScript("OnMouseUp", function(self, button)
if button == "RightButton" then
local mouseoverName = UnitName("mouseover") or "Unknown";
local reaction = UnitReaction("mouseover", "player") or 10;
if reaction < 5 then
DEFAULT_CHAT_FRAME:AddMessage("Stopped Attack on: "..mouseoverName);
MouselookStop();
else
DEFAULT_CHAT_FRAME:AddMessage(mouseoverName.." is friendly! "..reaction);
end
end
end)
The code I have should be working (from what I can tell) - but it's not. The code always returns Unknown & 10. If I swap out mouseover for player it works fine (but doesn't actually give me the data I need).
Also, if I swap out and hook-into OnMouseDown it also works, but then I can't actually interrupt the attack.
Any insight on why it's not working or how to fix it would be appreciated... Also if there is just a better way to do things I'm all ears.
UnitName("mouseover") indeed returns nil while any mouse button is pressed.
This is quite a smart idea to prevent attacking hostile units with mouse click. It probably doesn't work because Blizard really made sure to protect any possible thing to do with the WorldFrame that could be abused.
https://wow.gamepedia.com/API_GetCursorInfo sadly also doesn't return if the cursor is currently the sword icon, only if it's holding something.

Using XCode (Swift) to develop iOS app for school and label properties won't refresh

I am a reading teacher (I don't teach programming) at a school for students with LDs. We needed an app to flash 20 words in a random order for a set number of milliseconds, then black out the word for a set number of ms, then proceed through the list of 20 words. I dabbled in programming 15 years ago but have never developed an app.
The logic works ok, but I know there are better ways to do it - I just don't have time to learn all the ins and outs right now! My only problem is that the label won't update until the entire routine completes so no words show. I have tried a bunch of different techniques recommended on this site, but have not gotten anything to work. Is there a simple solution - seems like the layoutIfNeeded is a recommended technique but I don't seem able to implement correctly.
Any help is appreciated!
#IBAction func cmdStart(_ sender: Any) {
// the main logic
self.view.layoutIfNeeded()
var x = arc4random() % 20;
var i:Int = Int(x)
var num = 0
while num < 20 {
num += 1
self.lblDisplay.backgroundColor=UIColor.white
while wordUsed[i] == 1
{
x = (arc4random() % 20)
i = Int(x)
}
// output
print ("word is \(wordList[i])")
self.lblDisplay.text = wordList[i]
self.lblDisplay.backgroundColor=UIColor.white
self.view.layoutIfNeeded()
//delay based on slider
let delTimeWord = (self.sldDelay.value)*1000
usleep(useconds_t(delTimeWord))
//blackOut duration based on slider
let delTimeBlack = (self.sldVisible.value)*1000
usleep(useconds_t(delTimeBlack))
self.lblDisplay.backgroundColor = UIColor.black
wordUsed[i]=1
}
}
In an iOS application, you need to let the "event loop" run. This is a loop run by the operating system that checks for input events, refreshes the screen, and generally keeps everything going. If you don't let the loop run, then an app "locks up" and stops doing anything.
The cmdStart method, which I assume is triggered by a button, is itself being called by the event loop. Rather than running your own loop within that method, what you should do is have that method set some state and maybe start a timer that will do things later, and then return so that the event loop can keep running.
So those variables that you currently have in your cmdStart should probably be properties of the view controller. Instead of calling usleep, start a timer that will fire at the appropriate time, and in the timer handler, do whatever the "next step" is.
You don't need to call layoutIfNeeded. Just set the label's text and color within your handler method, and when it returns the event loop will take care of updating the screen,
Sorry that I can't provide a complete example, but I'd recommend reading about NSTimer and looking for examples.

Save 2 different PFObjects eventually or fail both

Using Parse SDK for iOS, I have 2 tables :
Game
- UserA : Pointer <_User>
- UserB : Pointer <_User>
- Round : Number
- IsTurnOfUserA : Bool
RoundScore
- GameId : Pointer <Game>
- User : Pointer <_User>
- Score : Number
- etc
A game is done in 3 rounds between 2 users.
When a user ends a round, it toggles Game.IsTurnOfUserA and saves the score for the round to RoundScore table.
In iOS, I didn't find a way to update Game table AND save a RoundScore eventually (maybe later if there is no network).
Both must be done or none at all, but I don't want to end up with only one of the 2 query to be successful and the other one failed.
With Cloud Code, it should be easy to do so but there is no call eventually function.
Update: Maybe there is something to try with Parse's local database ? But I don't know that tool yet.
Important: RoundScore has a field that depends on Game. If Game Object is new, it doesn't have an ObjectId yet, but I still need to link it to the RoundScore Object.
Unfortunately it isn't possible with saveEventually.
What you would need to do is implement your own network checking code and call a cloud method that will save both. That would be the best option.
A hack you could try as an alternative is to save the combined data to another class and have a background job on the server turn that single temporary row into a row in each table, then remove the temporary row.
The drawbacks of this hack is that the background job can run every 15 minutes only, so there might be up-to 15 minutes delay. It also adds extra complexity and overhead to your app.
As Timothy Walters suggested, here is the hack without any background job:
I created a fake table that has the columns of both tables Game and RoundScore
GameAndRoundScore
- Game_UserA
- Game_UserB
- RoundScore_GameId
- RoundScore_Score
- etc
In Cloud Code, I added this function before save
Parse.Cloud.beforeSave("GameAndScoreRound", function(request, response) {
var Game = Parse.Object.extend("Game");
var game = new Game();
game.set("UserA", request.object.get("game_UserA"));
game.set("UserB", request.object.get("game_UserB"));
game.save.then(function(newGame) {
var RoundScore = Parse.Object.extend("RoundScore");
var roundScore = new RoundScore();
//roundScore.set(...)
return scoreRound.save();
}).then(function(newRoundScore) {
response.success();
});
});
Then for the fake table data, I can either leave it as it is or set a background job that empties it or even empty the table manually on the Parse Backend.

Creating lighting within Minecraft from the server?

I'm creating a bukkit plugin and it requires lighting to be added and I want to be able to accomplish this server side only so that users don't need special plugins to see the lighting. Could this be done? If I'm not mistaken rendering lighting has been server side before? I would also like this lighting to be colored and lighting sources to be invisible (lighting from coordinates is acceptable since the map will be set)
My fear, can it be done?
You could do this using:
p.sendBlockChange(Location, Material, Byte);
Location is the location of the block
Material is the material that you want the player to see
the Byte is the data, so in the block 43:8, you would use 8. If there is none, just use 0.
So, you could do this to send the block update to all players:
Location[] invisibleBlocks; //all Invisible locations
for(Player p : Bukkit.getOnlinePlayers()){ //get all online players
for(Location l : invisibleBlocks){ //get all invisible blocks
p.sendBlockChange(l, Material.AIR, 0); //send block change of AIR to the player
}
}
The only problem is that block changes get reset when a player unloads/loads the chunk that the change is in. So, to fix this, you could schedule a timer:
Location[] invisibleBlocks; //set this to the locations of all of the blocks you want to make invisible
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
public void run(){
for(Player p : Bukkit.getOnlinePlayers()){ //get all online players
for(Location l : invisibleBlocks){ //get all invisible blocks
p.sendBlockChange(l, Material.AIR, 0); //send block change of AIR to the player
}
}
}
},100);//delay time is 5 seconds (5 seconds * 20 ticks per second)
Then all you need to do is put glowstone in the the invisibleBlocks locations, and it will appear as air, but (should) still emit light.
One problem with this is that if a player tries to walk into the block, they will walk in half way, then get teleported back out. This is because the client thinks there isn't a block there, yet the server knows that there is, and when the player walks into the block, the server teleports them back out, making a jerky kind of motion.
If you put this somewhere where players can't walk into it, you should be good!

How could i make this function sleep for a certain amount of time?

So here's my problem. I have code set up that calls a function whenever my player is over its last destination in the a* pathfinding array...
public function rakeSoil(e:Event):void {
var:Cell = Grid.getCellAt(player.x/50, player.y/50);
if (cell.isWalkable == false) {
return;
else {
//here is where i want to do the sleep code so this doesnt happen straight away? If possible.
target.sprites = [grass];
}
}
thanks guys :)
Generally, the "right" way to delay execution of something is to use a Timer.
Hacking up some kind of a sleep function could cause problems, since Flash runs in a single thread, so you won't be able to do anything else while your function is running, including refreshing the screen (making your game appear as if it crashed, or at least started lagging).
If you're absolutely, positively sure you want to do this, you could call the getTimer() function in a loop to see if a certain amount of miliseconds has passed.

Resources