Jump to content

Recommended Posts

Im using this code at the moment, and Im trying to make it include my battleon.php only if both conditions are met, but at the moment it includes the page when the first condition (randbattle) is met.

 

if (($randbattle == "1") || ($enemy_hp == "0")) {
include ('battleon.php');
}

 

Can anyone tell me why it isnt working ? Thanks

ah so simple, thanks :)

 

I have another issue with the code I have come across.

 

if (($rand_battle == "1") || ($enemy_hp == "0")) {
include ('battleon.php');
}

 

$rand_battle is decided using rand (1, 5) and when the include file called battleon.php is included it spawns a enemy to fight, thats why I wanted it to include only if the enemys health is on 0. So it doesnt try and respawn before its even been killed. And the first line of battleon.php resets the characters health to 9999 so you can battle it.

 

but my issue is, once the characters health has been reset to full, the if statement is no longer valid, so as soon as the page refreshes (which it has to do quite a lot) the battleon file dissapears aswell as the enemy to fight.

 

Does anyone have any ideas as to how i can include my battleon.php file when $enemy_hp == "0" but for the include to stay?

 

I was thinking maybe making it so when the enemys health drops to 0, it updates a row in the database, and maybe that could control if the include stays or not, but i cant figure that out in my head lol, sorry if this has been very confusing

 

 

the if statement only includes the battleon.php page if the characters health is at 0

 

but my battleon.php page updates the characters health back to full, so it can be faught.

 

but then as soon as my main page is refreshed, because the characters not at 0 health, it no longer includes the file i need to fight the enemy.

 

originally, i was using this code to include my battle, but i had to click a button which would update my database to change the value of $battleon.

 

<?php
if ($battleon == "1") {
include 'battle.php'; }
}
?>

 

So i thought with the rand function, and only calling the battle page if the number '1' was generated by the function i could make the battle encounter random rather than having to start it manually.

 

 

I would set a session variable, 0 for fight ended, 1 for fight started.

 

So then you could call it:

if($_SESSION['fight'] == 0) {
//there is no fight currently, lets start one>
$_SESSION['fight'] = 1;
}
if($_SESSION['fight'] == 1) {
//Someone started a fight on the last page>
//Do fight stuff.
if($fight_is_finished) {
  //Let everyone know that fight is over.
$_SESSION['fight'] = 0;
}
}

 

If that even makes sense to you.

 

thanks guys :)

 

ive never done anything with session variables before and im feeling pretty stupid at the moment,

I understand a tiny bit of what you posted, i think :P

 

Do you know how i would incorporate it with my original code

 

<?php
if (($randbattle == "1") && ($battleon == "2")) {
include ('battleon.php');
}
?>

 

or is that no longer applicable for what i want it to do?

 

sorry to be so dumb

It's getting to the point where you're asking us to code for you.

 

This is the point that I stop helping. There is way too much involved with your script to simply give you something that you can copy and paste and make work. We can offer theories and snippets that you can refer to, but implementing those snippets in to your script is for you to do.

Oh, we will help you understand things better.

 

Sessions store a file on the server that contains all of the data you wish to store for a short period of time.  You can access that data in an array.  In order for the server to know what data to make available, it will set a cookie in the clients browser that contains a value that matches the file name the data is inside.  There is only 2 criteria to using sessions.

 

1. Start the session:

<?php
//this line MUST be called before ANY output to the page:
session_start();

 

2. You must save data to the session:

<?php
//this line MUST be called before ANY output to the page:
session_start();

$_SESSION['started'] = 'Yes, you have started a session.';

 

Now to use that session, is just as simple.

<?php
//this line MUST be called before ANY output to the page:
session_start();

//call the session:
if(!empty($_SESSION['started'])) {
echo $_SESSION['started']; //You should get an echo, on your first page refresh.
}
else {
$_SESSION['started'] = 'Yes, you have started a session.';
echo 'Session is not showing up currently, please refresh the page.';
}
?>

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.