-
Underdog to the Babes Coven
[Help] Stupid question really...
Lo,
I've got a stupid variables problem in an if statement;
Basically, every time the incrementing variable, "day" gets to 7, I want the variable "week" to go up by 1 (logically... lol).
But, it doesnt...
function weekrise() {
if(_root.day == 7 ){
_root.week+=1;
}
}
weekrise();
any ideas?
-
no problems there maybe if you post the rest of it... did you declare all your variables ?
-
Senior Member
I'm not sure exactly but u may want
code: function weekrise() {
if(_root.day > 6 ){
_root.week+=1;
_root.day=0
}
}
weekrise();
hope that helps
-
Underdog to the Babes Coven
//Date/Week Incremention
var dayIncrementExecutionSpeed = 1000;
var dayIncrementSize = 1;
var dayTriggerId = -1;
var weekIncrementExecutionSpeed = 1000;
var weekIncrementSize = 1;
var weekTriggerId = -1;
function incrementDay() {
day +=dayIncrementSize;
// Stop incrementing at 100
if(day == 7) {
// Stop the trigger
clearInterval(stockTriggerId);
clearInterval(creditTriggerID);
}
}
//function incrementWeek() {
// week += weekIncrementSize;
//}
function weekrise() {
if(_root.day == 7 ){
_root.week+=1;
}
weekrise();
}
function incrementCommerce() {
commerce += commerceIncrementSize;
if(commerce == 100) {
// Stop the trigger
clearInterval(commerceTriggerID);
}
}
function startTriggers() {
dayTriggerId = setInterval(incrementday, dayIncrementExecutionSpeed);
weekTriggerId = setInterval(incrementweek, weekIncrementExecutionSpeed);
}
startTriggers();
stop();
----
Thats pretty much the entire coding for the incremnting of the day and week variables (note that I got rid of the incrementing week variable as it isn't based on its own increase, its based on the increase of the days). Both day and week are variables in dynamic text boxes on the main stage... See any faults?
The extra code the previous poster suggested dint alter it either...
Last edited by krisinyork; 06-03-2004 at 02:49 PM.
-
_root.day = 0;
_root.week = 0;
function weekrise() {
if (_root.day == 6) {
_root.week += 1;
_root.day = 0;
}
}
_root.onEnterFrame = function() {
_root.day += 1;
weekrise();
trace(week);
};
dunno what context your doing this in but function works try this on a frame script...
-
didnt see.. previous post heh
-
Underdog to the Babes Coven
lol puzzling eh?
If anyone knows a MUCH easier way of incrementing variables, thats takes less than half the code seen above, pllllllllease let me know.
Bloody code >:-( why won't it work.
-
how is it supposed to increment if is not repeated ?
-
Underdog to the Babes Coven
It does repeat, it repeats the function with the given guidelines by that function, i.e. speed of incremement, amount etc.
-
SaphuA
:)
Hey,
I first want to say that this post is more something for the Actionscript or Newbies forums. Don't take it personaly, but when writing a game, it's is a MUST that you understand the basics of AS.
Now because I'm practising for writing my tutorials, I will try to explain this
You'll first start with declaring 2 variables in frame1 of your movie:
code: var day = 1; //--Assuming that 1 is monday and 7 is sunday---
var week = 1;
This will create the variables and give them both the value 1.
Now we want days to pass, but we want to take care of weeks. This will be done in the folowing function:
code: function addDay(amount){
day += amount;
while(day>7){
week += 1;
day -= 7;
}
trace("Day: "+day);
trace("Week: "+week);
trace("---------"
}
Line one: This creates a function with an argument 'amount'.
Line two: Whatever value was added in the argument, will be added to 'day'
Line three: This while loop, will keep looping untill day>7 returns false.
Line for and five: When there are more then 7 days passed, it will add one to week. A week meens 7 days, so they are removed from the 'day' variable. If the value from line 3 is still true, it will repeat it again.
Line sex to eight: This will visualize the variables once the whileloop is completed.
Calling the function is now very easy:
code: addDay(12); //--Will add 12 days---
You can put this on a button also:
code: on(release){
addDay(3);
}
I hope I could explain this correct...
Good luck,
SaphuA
Edit: Haha! No one replied when I was writing this post, and now look at all the posts above
-
think i understand better now the prob you were having does this help ?
var day = 0;
var week = 0;
// added week_count;
var week_count = 1;
var dayIncrementExecutionSpeed = 1000;
var dayIncrementSize = 1;
var dayTriggerId = -1;
var weekIncrementExecutionSpeed = 1000;
var weekIncrementSize = 1;
var weekTriggerId = -1;
function incrementDay() {
day += dayIncrementSize;
// Stop incrementing at 100
if (day == 7) {
// Stop the trigger
clearInterval(stockTriggerId);
clearInterval(creditTriggerID);
}
}
//function incrementWeek() {
// week += weekIncrementSize;
//}
function weekrise() {
if (_root.day == 7*week_count) {
week_count += 1;
_root.week += 1;
}
}
function incrementCommerce() {
commerce += commerceIncrementSize;
if (commerce == 100) {
// Stop the trigger
clearInterval(commerceTriggerID);
}
}
function startTriggers() {
dayTriggerId = setInterval(incrementday, dayIncrementExecutionSpeed);
weekTriggerId = setInterval(incrementweek, weekIncrementExecutionSpeed);
}
_root.onEnterFrame = function() {
incrementDay();
weekrise();
trace("week"+week);
trace("day"+day);
startTriggers();
};
-
Senior Member
Agreed with Saph, but im posting this because i went to the trouble of correcting it
code:
//Date/Week Incremention
var dayIncrementExecutionSpeed = 1000;
var dayIncrementSize = 1;
var dayTriggerId = -1;
var day = 1;
var weekIncrementExecutionSpeed = 1000;
var weekIncrementSize = 1;
var weekTriggerId = -1;
var week = 1;
function incrementDay() {
day += dayIncrementSize;
// Stop incrementing at 100
if(day == 7) {
// Stop the trigger
clearInterval(stockTriggerId);
clearInterval(creditTriggerID);
}
}
function incrementWeek() {
if(day == 7 ){
day = 1;
week += 1;
}
}
function incrementCommerce() {
commerce += commerceIncrementSize;
if(commerce == 100) {
// Stop the trigger
clearInterval(commerceTriggerID);
}
}
function startTriggers() {
dayTriggerId = setInterval(incrementDay, dayIncrementExecutionSpeed);
weekTriggerId = setInterval(incrementWeek, weekIncrementExecutionSpeed);
}
startTriggers();
stop();
fracture2 - the sequel
fracture - retro shooter
blog - games, design and the rest
"2D is a format, not a limitation" -Luis Barriga
-
Underdog to the Babes Coven
ARGGHHHHHHHHH! *screams and runs*
-
Underdog to the Babes Coven
*tiptoes back and sighs*.
Ahhh. Heavenly Random. Where would I be without ye eh?
-
Senior Member
Sometimes i think this whole forum would fall apart without me
fracture2 - the sequel
fracture - retro shooter
blog - games, design and the rest
"2D is a format, not a limitation" -Luis Barriga
-
Underdog to the Babes Coven
Heheheh, contact me btw if you're still up for doing some of that club music.
Ive actually got 1 more v. stupid question... lol...
My little dudes moving about, doing his bits and bobs and - BHAM - hits a wall. I need him to go in the opposite direction whatever he was moving in (i.e. x+ -- hits a wall -- x-).
Tried;
this._x-=_root.con1speed;
if(this.hitTest(_root.wwall)){
_root.con1._x+=_root.con1speed;
}
But the MC only freezes on the wwall mc boundary. any ideas?
Last edited by krisinyork; 06-03-2004 at 03:25 PM.
-
Senior Member
code:
if(this.hitTest(_root.wwall)){
_root.con1speed = -_root.con1speed;
}
OR, as a clever man once said... use tiles
fracture2 - the sequel
fracture - retro shooter
blog - games, design and the rest
"2D is a format, not a limitation" -Luis Barriga
-
Underdog to the Babes Coven
Tiles = Evil Ta, will have a gleg n see if its working.
-
Since this is kind of time/date related, how can I set a text box to always have a certain decimal amount. The clock on my game takes the hour variable, minute variable, and puts them together. But if my hour is at 04, it just converts it to 4. Anyway I can keep that 0 in there? Do I make it a string?
Thanks
DUN DUN... DUN!!
Yep, bored...
-
Feeling adventurous?
code:
//the var hour holds the current hour.
if (hour<10) {
hourdisplay = "0"+hour;
} else {
hourdisplay = hour;
}
and then set the textbox variable to hourdisplay
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|