Flash shared object always gets reset - string

So in my game, you want to make the potato as big as possible. The first time you play it, the highscores work fine,giving you a highscore and saving it. The problem is that whenever you play the game, the highscore is always reset to your current score, which means that even if you get a lower score then your previous highscore, it saves your current score as the highscore. my code looks like this:
var savedstuff:SharedObject = SharedObject.getLocal("myStuff");
if (savedstuff.data.bestScore = 0) {
savedstuff.data.bestScore = 1
}
bigness.text = finish.toString();
if (finish > savedstuff.data.bestScore){
savedstuff.data.bestScore = finish;
}
best.text = savedstuff.data.bestScore.toString();
savedstuff.flush();
where bigness is a textbox displaying your current score, best is a textbox displaying your highscore and bestScore is where the best score is stored. I have the line "if (finish > savedstuff.dada.bestScore)" which should make the overwrite only occur if you get a higher score, but it seems to just ignore that line. my game is here
http://www.kongregate.com/games/pwnedcat/grow-a-potato
any help is appreciated. I just started flash so I really don't know anything. :(

Check the condition, it should be
savedstuff.data.bestScore == 0
Instead of
savedstuff.data.bestScore = 0

Related

How to write code to show who has won the game

i have made a cannon shooting game for two player, the aim is to break the castle down and then try to land the cannon ball onto the opponent but the problem is idk how to write code to show who has won the game when the game is over and all i know is that the code will need to written in the game over section & I am new to code as well
void CMyGame::OnUpdate()
{
if (m_mode == MODE_SHOOT)
{
/////////////////////////////////////////////////
// this code will only be executed while shooting
// TODO: 1. Add the gravitation
m_ball.Accelerate(0, -8);
// TODO: 2. Check if cannon hit? game over?
if (m_ball.HitTest(m_cannons[1 - m_turn]))
{
GameOver();
}
// TODO: 3. Check if the ball is outside the screen. Test the following cases:
// - ball to the left of the screen
if (m_ball.GetX() < 0)
NextTurn();
// - ball to the right of the screen (screen width = 800)
if (m_ball.GetX() > 800)
NextTurn();
// - ball below the screen
if (m_ball.GetY() < 0)
NextTurn();
// TODO: 4. Check if the ball hit the castle?
for each (CSprite * pSprite in m_castle)
{
if (m_ball.HitTest(pSprite))
NextTurn();
}
}
// Check if the castle has taken damage
for (CSprite* pSprite : m_castle)
{
if (m_ball.HitTest(pSprite))
pSprite->Delete();
}
m_castle.delete_if(deleted);
// Update the ball's position
m_ball.Update(GetTime());
the part i need help on is how to write code that will show who has won the game
// called when Game is Over
void CMyGame::OnGameOver()
{
m_cannons[1 - m_turn]->SetImage("fire");
m_mode = MODE_GAMEOVER;
}
Hard to say without seeing the rest of your code and info on how your game works, but you can follow something like this:
Assuming you can check when a cannon lands somewhere and can track the % hit points of each player (which I believe you can do considering you have gravity planned in your given code):
Write a function which is called each time a cannon ball lands, check if the ball has dealt the final blow on the opponent's character. From what you say, you probably do not need to do this check until the castle has been broken down. So something along the lines of if(!castleBroken) {return;} at the start of the function would only check the opponent's HP if the castle is broken (again, assuming that the opponent can only take damage if the castle is broken). Here, castleBroken is a bool which starts as false and becomes true when the cannon has broken the opponent's castle.
This is a similar idea to a Tic-Tac-Toe game I wrote in the past, where after each move, I would check the board state. If the game was over, the game over screen would be printed with the winner declared, or in some cases, a draw.

how to change the position of textinput in python/turtle

#welcome Player 1 and print the players name
player1 = sc.textinput("Name of Player X", "Whats your name? ")
movingTurtle.penup()
movingTurtle.goto(-275, 240)
movingTurtle.pendown()
sc.wel_Player1 = movingTurtle.write("Welcome Player X: "+player1,
font=FONT2)
this code works fine , a little "message-box" popĀ“s up and asks the 1st player for his name -- the problem is that i cant change the position of that TEXTINPUT-BOX -- i dont even know, if this is possible
I've had the same question and I've looked everywhere for an answer!
Unfortunately, from what I've found, there doesn't seem to be any way to modify the position or general look of a textinput box.
Have a look at -> This similar post
This might be what you're looking for.
If anyone can actually propose a different way, that would be much appreciated however my conclusion is that a textinput dialog box cannot be modified sadly.
What I've done is commit to the look by adding a black backdrop-type box behind it and making it a bit more obvious and professional that way.
#the black backdrop
useroptionboxback = turtle.Turtle()
useroptionboxback.speed(0)
useroptionboxback.shapesize(stretch_wid=6.8,stretch_len=10)
useroptionboxback.shape('square')
useroptionboxback.color('black')
useroptionboxback.penup()
useroptionboxback.goto(-215,255)
useroptionboxback.direction = 'stop'
#the tetinput box
title1 = 'Menu'
prompt1 = 'Please type a number.'
useroptionbox = turtle.textinput(title1, prompt1)
wn.update()
Example Screenshot
I would recommend doing something like this if you find what the guy on the link is saying too confusing.

Why isn't my path2d position updating?

I created a new path2d following the instructions in the my first game article: http://docs.godotengine.org/en/3.0/getting_started/step_by_step/your_first_game.html
I wanted to move the "box" on screen so that I could see how the mobs spawn in, but when I ran the scene, it stayed off screen.
I created a new path2d, centered this one in the middle of the screen, and it works like I wanted it to, but now I moving this one in the editor doesn't update the position in game.
What's going on?
Thanks
func _on_mobtimer_timeout():
$mobtimer.wait_time = 0.1 + randf() / 2
$mobspawn/moblocation.set_offset(randi())
var mob = Mob.instance()
add_child(mob)
var direction = $mobspawn/moblocation.rotation + PI/2
mob.position = $mobspawn/moblocation.position
direction += rand_range(-PI/8, PI/8)
mob.rotation = direction
mob.set_linear_velocity(Vector2(rand_range(200, 200 + score * 30), 0).rotated(direction))
A Node2D's position property is relative to it's parent's position. The code from the Dodge The Creeps tutorial assumes that MobPath is located at 0, 0 and fails when that assumption is false.
In your case you are taking a MobSpawnLocation's position relative to MobPath and then setting it as the new Mob's global position.
Luckily Node2D's have another property that we can use in these circumstances global_position. It can be used like this:
mob.position = $mobspawn/moblocation.global_position
http://docs.godotengine.org/en/stable/classes/class_node2d.html#member-variables
This isn't a full solution, but I found a weird workaround. Instead of changing the position in the editor, if you use the nodes on the orange box (at the intersection of orange and blue), you can kind of alternate to move the box around.

Any way to get a HaxeFlixel group to clear out?

There is a too long, didn't read version down below.
So I've been making a little game in which the player has to click on a grid of bricks that matches the color of the needed brick in the upper right hand corner of the screen. After they click on the needed color, the bricks explode and the bricks of the same color next to them explode as well creating combos. That leaves holes in the grid so I have to somehow reset the grid itself without resetting the gamestate itself. I've got something working right now which is this:
private function ResetNow():Void
{
if (Restter == 1) Restter = 0;
//if this block is up here, same results
/*
wantedBricks.kill();
wantedBrik._changeColor = FlxMath.rand(0, 2);
bricks.autoReviveMembers = true;
bricks.revive();
*/
Restter = 0;
//Removes stray detectors so the neverending combo bug won't occur
for (stray in dets.members) stray.kill();
if (Restter == 0)
{
wantedBricks.kill();
wantedBrik._changeColor = FlxMath.rand(0, 2);
bricks.autoReviveMembers = true;
bricks.revive();
wantedBricks.autoReviveMembers = true;
wantedBricks.revive();
for (zgem in bricks.members) zgem.EQUITYCHECK = FlxMath.rand(0, 2);
}
//add(bricks);
Restter = 1;
}
So, again, I have a grid of blocks set up at create, that is group bricks. And I have a sprite in the upper right corner which is wantedBrik. What happens during gameplay, is the player clicks on the bricks that matches the wanted bricks to clear them out of the grid. When there are no more wantedBricks(a group), it is supposed to reset the grid, and change the color of the wantedBrik. I also have it somewhere else in the code that if a member of the big grid's EQUITYCHECK(basic object hacked in value) is equal to the wantedBrik, add it to the wantedBricks(which, is why I'm checking for no more of them). So, what happens?
Well, if the color of the wantedBrik doesn't change, everything's fine and resets like normal. the wantedBricks group acurately counts the bricks that actually match the wantedBrik's color. And when it does change, for some reason, gameplay is normal. BUT, wantedBricks not only thinks that the old color is still needed, but it also thinks the new color is still needed too. So when the player clicks the new needed color bricks, they do explode, but because wantedBrik thinks the old color is still wanted, it doesn't hit null and the grid won't reset.
What can I do to make sure that wantedBricks behaves correctly after a color change?
TL;DR version: I need to get a Haxe array to forget or lose old numbers. How can I do this?
The "Pirate Pig" sample may be useful to you. Since it is a puzzle game, there may be some similar problems that were solved there. You can find it using openfl create or nme create depending on which you are currently using.
You can create a simple array like this:
var myArray = [];
You can also type arrays, like this:
var numbers = new Array<Float>();
Then you can use push(), concat() and other array methods.

SVG - raphael: storing last path selected so element data can be changed

The current state
As from my link you can pick different regions on the map and everything seems to be working until you re-select a county you have selected before. Data values stored with each path decide if it isSelected or notSelected. I have no problem in changing the element data just clicked with this but I can't find a way of storing the last element selected in a way that I can change it's element data. Which means I first have to click on the previous county to set it's element data to notSelected
First I define var currentcountyselected = "";. This allows me to store the paths[arr[this.id]].name;. When I click on a new path I can make the last path fill change with $('#'+currentcountyselected).attr({fill: attributes.fill});
In Raphael's for loop I set obj.data('selected', 'notSelected'); so all path elements are set to notSeelected.
So what I need is some way to store the last path so I can change it's element data
This is the click function cleaned up from live example.
obj.click(function(){
if(this.data('selected') == 'notSelected')
{this.animate({fill: '#698B22' }, 300);
this.data('selected', 'isSelected');
$('#'+currentcountyselected).attr({fill: attributes.fill});
paths[arr[this.id]].value = "isSelected";
currentcountyselected = paths[arr[this.id]].name;
}
else
{this.animate({fill: '#32CD32'}, 300);
paths[arr[this.id]].value = "notSelected"; /* set path value*/
this.data('selected', 'notSelected');
}
});/* end mark selections */
I've been working on this project for a while and the client now wants the interface to work differently. This has really ate up my hourse.
EDIT:Although I have found a solution by simply taking out the if/else I would still like to know how to get at element data in a previous path (or any path for that matter).
Here is my solution, posted as it might help someone. The link in my question has problems with click happy users.
Globals
var previouscountyselected = "Mayo"; /* default start, can be any county(path) */
var start = true;
var past = null;
Changed code
obj.click(function(){
if(paths[arr[this.id]].value == 'notSelected')
{
this.animate({fill: '#698B22'}, 200);
paths[previouscountyselected].value = "notSelected";
paths[arr[this.id]].value = "isSelected";
previouscountyselected = paths[arr[this.id]].name;
if (!start && past != this)
{
past.animate({ fill: '#fff' }, 200);
}
past = this;
start = false;
}
else if(paths[arr[this.id]].value == 'isSelected')
{
this.animate({fill: '#32CD32'}, 200);
paths[arr[this.id]].value = "notSelected"; /* set path value */
}
});
Overview
if (!start && past != this) is a little unusual and is required or animated fades get messed up and choppy. The fade is not triggered if it is the first time a path is clicked and if you just hammer clicks on one path it doesn't fade to white. The main if/else handles the actual control value.
Until I get a jsfiddle up this link will demonstrate the desired behaviour.
Note! the drop menu in this link does not work.
Click happy friendly

Resources